地址:http://codeforces.com/contest/371/problem/C
思路:一开始自己做,做到一半发现要考虑的条件太多,思维不严谨的话会丢失一些可能性而错误,所以放弃了。赛后找了大神的代码看了下,27行,真简便o.0,这里把按大神思路写的代码写出。找到最大可能值,最小可能值,二分查找最终答案。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
//#include<algorithm>
using namespace std;
#define LL __int64
int main()
{
char s[110];
gets(s);
LL hb=0,hs=0,hc=0;
for(int i=0;i<strlen(s);i++)
{
if(s[i]=='B') hb++;
if(s[i]=='S') hs++;
if(s[i]=='C') hc++;
}
LL nb,ns,nc;scanf("%I64d%I64d%I64d",&nb,&ns,&nc);
LL pb,ps,pc;scanf("%I64d%I64d%I64d",&pb,&ps,&pc);
LL r;scanf("%I64d",&r);
LL ll=0,rr=r+nb+ns+nc; //关键在最大值确定的问题上,最大的可能值是你有的钱数加上你有的材料数
while(rr-ll>1)
{
LL mid=(ll+rr)/2,t=r;
if(mid*hb>nb) t-=(mid*hb-nb)*pb;
if(mid*hs>ns) t-=(mid*hs-ns)*ps;
if(mid*hc>nc) t-=(mid*hc-nc)*pc;
if(t>=0) ll=mid;else rr=mid;
}printf("%I64d\n",ll);
return 0;
}