二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers
2015-07-25 18:07
423 查看
题目传送门
/* 题意:一个汉堡制作由字符串得出,自己有一些原材料,还有钱可以去商店购买原材料,问最多能做几个汉堡 二分:二分汉堡个数,判断此时所花费的钱是否在规定以内 */ #include <cstdio> #include <algorithm> #include <cmath> using namespace std; typedef long long ll; const int MAXN = 1e2 + 10; const int INF = 0x3f3f3f3f; char ham[MAXN]; ll nb, ns, nc; ll pb, ps, pc; ll b, s, c; ll m; bool check(ll x) { ll cost = 0; if (b * x > nb) cost += (b * x - nb) * pb; if (s * x > ns) cost += (s * x - ns) * ps; if (c * x > nc) cost += (c * x - nc) * pc; return cost <= m; } int main(void) { //Codeforces Round #218 (Div. 2) C. Hamburgers scanf ("%s", &ham); scanf ("%I64d%I64d%I64d", &nb, &ns, &nc); scanf ("%I64d%I64d%I64d", &pb, &ps, &pc); scanf ("%I64d", &m); b = s = c = 0; for (int i=0; ham[i]; ++i) { if (ham[i] == 'B') b++; else if (ham[i] == 'S') s++; else c++; } ll l = 0, r = 1e13; while (l + 1 < r) { ll mid = (l + r) >> 1; if (check (mid)) l = mid; else r = mid; } printf ("%I64d\n", l); return 0; }
相关文章推荐
- javascript实现动态导入js与css等静态资源文件的方法
- C++ 继承与接口 知识点 小结(一)
- HDU1312 Red and Black 解读
- 我关注的一周技术动态2015.7.26
- DNA Sorting(排序)
- MD5Util
- Maven详解
- LeetCode 1 search in rotated array
- 面向对象第四天
- 设置C# Windows 服务与桌面交互
- DIV+CSS中标签dl dt dd常用的用法
- 统计学习笔记——统计学习三要素
- DaoUtil
- 【笔记】Loadrunner添加OS类型为Windows的服务器(Win7)
- 工厂模式
- maven基础学习
- python,list
- JavaWeb 中乱码过滤器的代码
- python 字符处理代码 1.0
- 报错:Request failed: unacceptable content-type: text/html