C. Hamburgers
来源:互联网 发布:淘宝怎么举报别人盗图 编辑:程序博客网 时间:2024/05/22 04:29
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.
Polycarpus has nb pieces of bread, ns pieces of sausage and nc pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are pb rubles for a piece of bread, ps for a piece of sausage and pc for a piece of cheese.
Polycarpus has r rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers nb, ns, nc (1 ≤ nb, ns, nc ≤ 100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers pb, ps, pc (1 ≤ pb, ps, pc ≤ 100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer r (1 ≤ r ≤ 1012) — the number of rubles Polycarpus has.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the%I64d specifier.
Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.
BBBSSC6 4 11 2 34
2
BBC1 10 11 10 121
7
BSC1 1 11 1 31000000000000
200000000001
代码:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
char recipe[105];
int main()
{
int cun_b,cun_s,cun_c,leftb,lefts,leftc;
int n1,n2,n3,p1,p2,p3;
__int64 r,tmp;
scanf("%s",recipe);
scanf("%d%d%d",&n1,&n2,&n3);
scanf("%d%d%d",&p1,&p2,&p3);
scanf("%I64d",&r);
int i;
cun_b=cun_s=cun_c=0;
for(i=0;i<strlen(recipe);i++)
{
if (recipe[i]=='B')
{cun_b++;continue;}
if (recipe[i]=='S')
{cun_s++;continue;}
if (recipe[i]=='C')
{cun_c++;continue;}
}
if (cun_b)
tmp=n1/cun_b;
if (cun_s)
if (tmp> n2/cun_s )tmp=n2/cun_s;
if (cun_c)
if (tmp> n3/cun_c ) tmp=n3/cun_c;
leftb=n1-tmp*cun_b;
lefts=n2-tmp*cun_s;
leftc=n3-tmp*cun_c;
int tmpl=leftb;
if (tmpl<lefts)
tmpl=lefts;
if (tmpl<leftc)
tmpl=leftc;
while (tmpl--)
{
if (leftb<cun_b && p1*(cun_b-leftb)<=r)
{
r-=p1*(cun_b-leftb);
leftb=cun_b;
}
if (lefts<cun_s && p2*(cun_s-lefts)<=r)
{
r-=p2*(cun_s-lefts);
lefts=cun_s;
}
if (leftc<cun_c && p3*(cun_c-leftc)<=r)
{
r-=p3*(cun_c-leftc);
leftc=cun_c;
}
if (leftb>=cun_b&& lefts>=cun_s && leftc>=cun_c)
{
tmp++;
leftb-=cun_b;
lefts-=cun_s;
leftc-=cun_c;
continue;
}
break;
}
//////////////////////////////////////////////////////////////////////////
tmp+= r/(p1*cun_b+p2*cun_s+p3*cun_c);
r= r%(p1*cun_b+p2*cun_s+p3*cun_c);
////////////////////////////////////////////////////////////////////////
printf("%I64d\n",tmp);
return 0;
}
主要是第一次先做//////////////////////////////////////////////////////////////////////////内的,导致结果不是最优,因此调换了一下顺序,由于n1n2n3最大只有100,所以先穷举一次。再把剩下的求商一次就可以得到答案了。
- C. Hamburgers
- C. Hamburgers
- CodeForces 371C Hamburgers
- Codeforces 371C Hamburgers
- CodeForces-218C Hamburgers
- Codeforces 371C Hamburgers
- CodeForces 371C Hamburgers
- 【CodeForces】[371C]Hamburgers
- CodeForces 371C Hamburgers
- CodeForces 371C Hamburgers
- Hamburgers [CF-371C]
- C. Hamburgers----二分
- Hamburgers
- Hamburgers
- Hamburgers - CodeForces 371C 二分
- CodeForces 371C Hamburgers(二分)
- 二分-Codeforces 371C Hamburgers
- Codeforces 371C Hamburgers 【二分】
- servlet
- ESTORE OPENCART 清爽现代主题模板 ABC-0063
- SharePoint 2013 Power view ”bing的地图背景对此区域不可用“ 解决方法
- android 仿网易新闻滑动tab栏,HorizontalScrollView和rediogroup实现
- hadoop2理解读取文件在流程
- C. Hamburgers
- shell 下 ls 命令的各种使用说明
- APP创业——时不待人
- BZOJ 3897 Power 分治
- BZOJ-2716-天使玩偶angel-CDQ分治
- Reverse Integer
- ASP.NET MVC的JsonResult
- 第一章第8小题
- android 图片处理(截取,缩放)