cf C. Hamburgers

http://codeforces.com/contest/371/problem/C

二分枚举最大汉堡包数量就可以。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 
 6 char s[110];
 7 int n1,n2,n3;
 8 int p1,p2,p3;
 9 __int64 m;
10 int t1,t2,t3;
11 bool ok(__int64 x)
12 {
13     __int64 ans=0;
14     if(x*t1-n1>=0)
15     ans+=(__int64)((x*t1-n1)*p1);
16     if(x*t2-n2>=0)
17     ans+=(__int64)((x*t2-n2)*p2);
18     if(x*t3-n3>=0)
19     ans+=(__int64)((x*t3-n3)*p3);
20     if(ans<=m) return true;
21     else return false;
22 }
23 
24 int main()
25 {
26     while(scanf("%s",s)!=EOF)
27     {
28         t1=0; t2=0; t3=0;
29         scanf("%d%d%d",&n1,&n2,&n3);
30         scanf("%d%d%d",&p1,&p2,&p3);
31         __int64 max1=(n1>n2?n1:n2)>n3?(n1>n2?n1:n2):n3;
32         scanf("%I64d",&m);
33         int k=strlen(s);
34         for(int i=0; i<k; i++)
35         {
36             if(s[i]=='B') t1++;
37             else if(s[i]=='S') t2++;
38             else if(s[i]=='C') t3++;
39         }
40         __int64 l=0,r=m+max1;
41         __int64 ans=0;
42         while(l<=r)
43         {
44             __int64 mid=(l+r)/2;
45             if(ok(mid))
46             {
47                 ans=mid;
48                 l=mid+1;
49             }
50             else
51                 r=mid-1;
52         }
53         printf("%I64d
",ans);
54     }
55     return 0;
56 }
View Code
原文地址:https://www.cnblogs.com/fanminghui/p/4069797.html