Codeforces 371C Hamburgers (二分答案)
2024-08-29 15:41:53
题目链接 Hamburgers
二分答案,贪心判断即可。
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i(0); i < (n); ++i)
#define LL long long char str[1010];
LL len;
LL b, c, s, nb, nc, ns, pb, pc, ps;
LL money; bool judge(LL x){
LL mb = x * b;
LL ms = x * s;
LL mc = x * c; LL now_money = money;
if (mb > nb) now_money -= (mb - nb) * pb;
if (ms > ns) now_money -= (ms - ns) * ps;
if (mc > nc) now_money -= (mc - nc) * pc; return now_money >= 0LL;
} int main(){ scanf("%s", str);
len = strlen(str);
REP(i, len){
if (str[i] == 'B') ++b;
else if (str[i] == 'S') ++s;
else ++c;
} cin >> nb >> ns >> nc;
cin >> pb >> ps >> pc;
cin >> money; LL l = 0, r = 1e14;
while (l + 1 < r){
LL mid = (l + r) / 2;
if (judge(mid)) l = mid; else r = mid - 1;
} if (judge(r)) cout << r << endl; else cout << l << endl;
return 0; }
最新文章
- C#组合查询小Demo
- html画布
- C#多线程 线程池
- CURL学习和应用
- [Flex] PopUpButton系列——CornerRadius的运用
- Robolectric Test-Drive Your Android Code
- OCP-1Z0-051-题目解析-第14题
- 论JVM爆炸的几种姿势及自救方法
- ubuntu常用命令备忘
- 动态SQL2
- C# winform三种定时方法
- (转)Render Path
- spark-shell下有提示了,但是发现不能退格
- Solr导入MySQL数据之dataimport-handler
- random(随机模块)
- jQuery如何取得HiddenField值(转)
- Discuz论坛管理的问题汇总
- python 四种数值类型(int,long,float,complex)介绍
- Key Set---hud5363(快速幂)
- cf1060C. Maximum Subrectangle(思维 枚举)