C. Hamburgers
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

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.

Output

Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.

Sample test(s)
Input
BBBSSC 6 4 1 1 2 3 4
Output
2
Input
BBC 1 10 1 1 10 1 21
Output
7
Input
BSC 1 1 1 1 1 3 1000000000000
Output
200000000001

题意:就是给告诉你一个产品需要3种材料,然后给了你做一个产品各种材料需要多少以及你现在拥有的材料数和钱,让你求出最多可以做出多少产品。
分析:比赛的时候根本就没往2分方面想,然后一直在分类讨论,导致结果越分越多,最后把自己搞晕了,其实在之前我做过类似的题目,我这次竟然没往2分这方面去想!!
代码实现:
#include<stdio.h>
#include<string.h>
#include<math.h>
char str[];
__int64 n1,n2,n3,need1,need2,need3;
__int64 cost1,cost2,cost3,money,l,r; void solve()
{
__int64 mid,temp,res;
l=;r=money+n1+n2+n3;
temp=money;
while(l<=r)
{
mid=(l+r)/;
money=temp;
if(mid*need1>n1)
money=money-(mid*need1-n1)*cost1;
if(mid*need2>n2)
money=money-(mid*need2-n2)*cost2;
if(mid*need3>n3)
money=money-(mid*need3-n3)*cost3;
if(money<)
r=mid-;
else
{
res=mid;
l=mid+;
}
}
printf("%I64d\n",res);
} int main()
{
__int64 i;
scanf("%s",str);
need1=need2=need3=;
scanf("%I64d%I64d%I64d",&n1,&n2,&n3);
scanf("%I64d%I64d%I64d%I64d",&cost1,&cost2,&cost3,&money);
for(i=;str[i]!='\0';i++)
if(str[i]=='B')
need1++;
else if(str[i]=='S')
need2++;
else
need3++;
solve();
return ;
}

Codeforces Round #218 (Div. 2) C题的更多相关文章

  1. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  2. 二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers

    题目传送门 /* 题意:一个汉堡制作由字符串得出,自己有一些原材料,还有钱可以去商店购买原材料,问最多能做几个汉堡 二分:二分汉堡个数,判断此时所花费的钱是否在规定以内 */ #include < ...

  3. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  4. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  5. Codeforces Round #552 (Div. 3) A题

    题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...

  6. Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring

    D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  7. Codeforces Round #218 (Div. 2)

    500pt, 题目链接:http://codeforces.com/problemset/problem/371/A 分析:k-periodic说明每一段长度为k,整个数组被分成这样长度为k的片段,要 ...

  8. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

  9. Codeforces Round #425 (Div. 2))——A题&&B题&&D题

    A. Sasha and Sticks 题目链接:http://codeforces.com/contest/832/problem/A 题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sash ...

随机推荐

  1. Geoprocessor 使用

    在AO中使用Geoprocessor(ESRI.ArcGIS.Geoprocessor) 1.观察arcmap中的使用方法,明确各参数意义. 2.arctoolbox中参数对应为features/fe ...

  2. Activity Recognition行为识别

    暑假听了computer vision的一个Summer School,里面Jason J. Corso讲了他们运用Low-Mid-High层次结构进行Video Understanding 和 Ac ...

  3. java.lang.NoSuchFieldError: VERSION_2_3_0 报错解决方案

    java.lang.NoSuchFieldError: VERSION_2_3_0 at org.apache.struts2.views.freemarker.FreemarkerManager.c ...

  4. openwrt(路由器)的源码地址

    https://dev.openwrt.org/wiki/GetSource 路由器的源码地址

  5. YTU 2611: A代码完善--向量的运算

    2611: A代码完善--向量的运算 时间限制: 1 Sec  内存限制: 128 MB 提交: 256  解决: 168 题目描述 注:本题只需要提交填写部分的代码,请按照C++方式提交. 对于二维 ...

  6. MTK平台缩写

    HSPA:High Speed Packet Access smartphone application processor,高速分组接入的智能手机应用程序处理器 META mode:Mobile E ...

  7. BZOJ 2752 高速公路(road)(线段树)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2752 题意:给出一个数列A,维护两种操作: (1)将区间[L,R]之内的所有数字增加de ...

  8. ssh: Could not resolve hostname gitcafe.com: nodename nor servname provided, or not known

    今天 git push 的时候报如下错误: ssh: Could not resolve hostname gitcafe.com: nodename nor servname provided, o ...

  9. create-maximum-number(难)

    https://leetcode.com/problems/create-maximum-number/ 这道题目太难了,花了我很多时间.最后还是参考了别人的方法.还少加了个greater方法.很难. ...

  10. HNOI2008题目总结

    呜呼..NOI前一个月正式开始切BZOJ了……以后的题解可能不会像之前的零散风格了,一套题我会集中起来发,遇到一些需要展开总结的东西我会另开文章详细介绍. 用了一天的时间把HNOI2008这套题切了… ...