http://codeforces.com/contest/371/problem/C


直接二分能做的汉堡数,注意上界要开大一点。


完整代码:

/*15ms,0KB*/

#include<bits/stdc++.h>
using namespace std;
const long long mx = 1e13;///多开一位,因为结果可以略大于1e12
const char b[] = "BSC";

char cost[105];
long long n[3];

int main()
{
	gets(cost);
	int len = strlen(cost), i;
	for (i = 0; i < len; ++i)
		++n[strchr(b, cost[i]) - b];
	for (i = 3; i < 10; ++i)
		scanf("%I64d", &n[i]); ///技巧:分开读取输入太麻烦,不如写到一块,哪部分存什么意义的数自己清楚
	long long l = 0LL, r = mx, m, cost, buy;
	while (l + 1 < r) ///注意是l+1<r,不解释
	{
		m = (l + r) >> 1;
		cost = 0LL;
		for (i = 0; i < 3; ++i)
			if ((buy = n[i] * m - n[3 + i]) > 0)
				cost += buy * n[6 + i];
		cost <= n[9] ? l = m : r = m;
	}
	printf("%I64d", l);
	return 0;
}