CodeForces- 371C Hamburgers
发布时间:2020-12-16 07:19:15 所属栏目:百科 来源:网络整理
导读:#include iostream #include algorithm #include cmath #include stdio.h #include cstring #include string #include cstdlib #include queue #include stack #include set #include vector #include map #include list // #include using namespace std; s
#include <iostream> #include <algorithm> #include <cmath> #include <stdio.h> #include <cstring> #include <string> #include <cstdlib> #include <queue> #include <stack> #include <set> #include <vector> #include <map> #include <list> //#include <> using namespace std; string s; char ss[103]; int slen; int nb,ns,nc; int pb,ps,pc,pnum; long long mon; struct hum{ int bre; int sau; int che; long long price; }h[1]; long long money(long long mid) { long long a,b,c; a=mid*h[0].bre-nb; b=mid*h[0].sau-ns; c=mid*h[0].che-nc; if(a<0) a=0; if(b<0) b=0; if(c<0) c=0; return a*pb+b*ps+c*pc; } int main() { //汉堡的组成 cin>>s; slen=s.length(); strcpy(ss,s.c_str()); //结构体汉堡的初始化 h[0].bre=0; h[0].che=0; h[0].sau=0; h[0].price=0; for(int i=0;i<=slen;++i) { if(s[i]==‘B‘) h[0].bre++; if(s[i]==‘C‘) h[0].che++; if(s[i]==‘S‘) h[0].sau++; } //cout<<h[0].bre<<" "<<h[0].che<<" "<<h[0].sau<<" "<<endl;检测初始化好了没QAQ //材料的输入 scanf("%d%d%d%d%d%d",&nb,&ns,&nc,&pb,&ps,&pc); h[0].price=pb*h[0].bre+ps*h[0].sau+pc*h[0].che; cin>>mon; //------------材料的处理 long long l=0,r=1e15,mid=(l+r)/2; while(l<r) { if(money(mid)<=mon) l=mid+1; else r=mid; mid=(l+r)/2; } if(money(mid)>mon) cout<<mid-1<<endl; else cout<<mid<<endl; return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |