您的位置:首页 > 其它

二分搜索 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: