标签:
1 /*
2 题意:一个汉堡制作由字符串得出,自己有一些原材料,还有钱可以去商店购买原材料,问最多能做几个汉堡
3 二分:二分汉堡个数,判断此时所花费的钱是否在规定以内
4 */
5 #include <cstdio>
6 #include <algorithm>
7 #include <cmath>
8 using namespace std;
9
10 typedef long long ll;
11 const int MAXN = 1e2 + 10;
12 const int INF = 0x3f3f3f3f;
13 char ham[MAXN];
14 ll nb, ns, nc;
15 ll pb, ps, pc;
16 ll b, s, c;
17 ll m;
18
19 bool check(ll x) {
20 ll cost = 0;
21 if (b * x > nb) cost += (b * x - nb) * pb;
22 if (s * x > ns) cost += (s * x - ns) * ps;
23 if (c * x > nc) cost += (c * x - nc) * pc;
24 return cost <= m;
25 }
26
27 int main(void) { //Codeforces Round #218 (Div. 2) C. Hamburgers
28 scanf ("%s", &ham);
29 scanf ("%I64d%I64d%I64d", &nb, &ns, &nc);
30 scanf ("%I64d%I64d%I64d", &pb, &ps, &pc);
31 scanf ("%I64d", &m);
32 b = s = c = 0;
33 for (int i=0; ham[i]; ++i) {
34 if (ham[i] == ‘B‘) b++;
35 else if (ham[i] == ‘S‘) s++;
36 else c++;
37 }
38 ll l = 0, r = 1e13;
39 while (l + 1 < r) {
40 ll mid = (l + r) >> 1;
41 if (check (mid)) l = mid;
42 else r = mid;
43 }
44 printf ("%I64d\n", l);
45
46 return 0;
47 }
二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers
标签:
原文地址:http://www.cnblogs.com/Running-Time/p/4676325.html