题目链接:http://codeforces.com/problemset/problem/371/C
赤果果的大水题!!
题目大意:给你一个汉堡的配料,and现有的每种原料的个数,and每种原料的价格,and你有的money;问最多能做几个汉堡。
obviously 这道题具有 二分性质 Thus 直接二分答案 判断买x个汉堡时原料以及钱是否is enough;
第一眼看这道题,“哇,这是神题?”是的,我没戴眼镜;
Get down to the business,上代码
1 #include<cstdio> 2 #include<algorithm> 3 #include<cmath> 4 #include<iostream> 5 #include<cstdlib> 6 #include<string> 7 #include<cstring> 8 #include<queue> 9 #include<deque> 10 #include<stack> 11 #define LL long long 12 using namespace std; 13 char pl[105]; 14 int nb,ns,nc,pb,ps,pc,b,s,c; 15 LL r; 16 bool check(LL x){ 17 LL cb = max(((LL)b*x-nb)*pb,(LL)0); 18 LL cs = max(((LL)s*x-ns)*ps,(LL)0); 19 LL cc = max(((LL)c*x-nc)*pc,(LL)0); 20 if(cb+cs+cc <= r) return true; 21 else return false; 22 } 23 int main(){ 24 scanf("%s",pl); 25 for(int i = 0;i < strlen(pl);i++){ 26 if(pl[i] == 'B') b++; 27 else if(pl[i] == 'S') s++; 28 else if(pl[i] == 'C') c++; 29 } 30 scanf("%d%d%d",&nb,&ns,&nc); 31 scanf("%d%d%d",&pb,&ps,&pc); 32 scanf("%lld",&r); 33 LL l = 0,r = pow(10,12)*2,mid; 34 while(l < r){ 35 mid = (l + r)>>1; 36 if(check(mid)) 37 l = mid+1; 38 else r = mid; 39 } 40 printf("%lld ",l-1); 41 return 0; 42 }