[Codeforces]Hamburgers
来源:互联网 发布:人工智能技术 知乎 编辑:程序博客网 时间:2024/05/22 15:46
原题链接
Codeforces真是太棒了
全英文请自行翻译
二分
注意边界条件
再次因为这个错了
#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<cmath>#include<queue>#include<vector>#include<climits>#include<string>#include<cstdlib>#include<map>#include<ctime>#define MAX 1000000007#define LL long longusing namespace std;char h[105];LL len,i,y[4],nb,ns,nc,pb,ps,pc,t,t2;LL rub,l,r;LL check(LL x){ LL mon,ned; mon=0; ned=x*y[1]; if(ned>nb) mon+=(ned-nb)*pb; ned=x*y[2]; if(ned>ns) mon+=(ned-ns)*ps; ned=x*y[3]; if(ned>nc) mon+=(ned-nc)*pc; return mon<=rub; }int main(){ scanf("%s",h); len=strlen(h); for(i=0;i<len;i++) { if(h[i]=='B') y[1]++; if(h[i]=='S') y[2]++; if(h[i]=='C') y[3]++; } scanf("%I64d%I64d%I64d",&nb,&ns,&nc); scanf("%I64d%I64d%I64d",&pb,&ps,&pc); scanf("%I64d",&rub); r=1e12+100; while(l<=r) { LL mid=(l+r)/2; t=check(mid); if(t) l=mid+1; else r=mid-1; } t=check(r); if(t) printf("%I64d",r); else printf("0"); return 0;}
贪心
#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<cmath>#include<queue>#include<vector>#include<climits>#include<string>#include<cstdlib>#include<map>#include<ctime>#define MAX 1000000007#define LL long longusing namespace std;char h[105];LL i,len,y[4],n[4],p[4],cb,ans,rub;int main(){ scanf("%s",h); len=strlen(h); for(i=0;i<len;i++) { if(h[i]=='B') y[1]++; if(h[i]=='S') y[2]++; if(h[i]=='C') y[3]++; } scanf("%I64d%I64d%I64d",&n[1],&n[2],&n[3]); scanf("%I64d%I64d%I64d",&p[1],&p[2],&p[3]); scanf("%I64d",&rub); cb=p[1]*y[1]+p[2]*y[2]+p[3]*y[3]; while((n[1]||n[2]||n[3])&&rub) { if(!y[1]) n[1]=0; if(!y[2]) n[2]=0; if(!y[3]) n[3]=0; if(y[1]) { if(n[1]>y[1]) n[1]-=y[1]; else { rub-=(y[1]-n[1])*p[1]; n[1]=0; if(rub<0) break; } } if(y[2]) { if(n[2]>y[2]) n[2]-=y[2]; else { rub-=(y[2]-n[2])*p[2]; n[2]=0; if(rub<0) break; } } if(y[3]) { if(n[3]>y[3]) n[3]-=y[3]; else { rub-=(y[3]-n[3])*p[3]; n[3]=0; if(rub<0) break; } } ans++; } if(rub>0) ans+=rub/cb; printf("%I64d",ans); return 0;}
阅读全文
0 0
- [Codeforces]Hamburgers
- CodeForces 371C Hamburgers
- Codeforces 371C Hamburgers
- CodeForces-218C Hamburgers
- Codeforces 371C Hamburgers
- CodeForces 371C Hamburgers
- 【CodeForces】[371C]Hamburgers
- CodeForces 371C Hamburgers
- CodeForces 371C Hamburgers
- Codeforces Round #218 Hamburgers
- Hamburgers - CodeForces 371C 二分
- CodeForces 371C Hamburgers(二分)
- 二分-Codeforces 371C Hamburgers
- Codeforces 371C Hamburgers 【二分】
- Hamburgers
- Hamburgers
- CodeForces 371C Hamburgers (二分)
- CodeForces 371C-Hamburgers(二分搜索)
- 打印出漂亮的json use python command python -m json.tool
- Glide的使用,加载图片只要一句话
- mybatis日期查询
- SGI特殊空间配置器std::alloc
- Android 系统默认参数的修改
- [Codeforces]Hamburgers
- Java基础之--内存划分
- kubernetes free data blocks which is less than minimum required
- Linux学习笔记
- 【Jquery学习】第五部分
- Html去掉隐藏字符解决办法
- Log4j 根据日期生成日志目录
- 高版本sql server数据库复制到低版本sql server数据库
- Node.js Buffer