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. Eclipse项目的导入跟导出

    1.导入项目 当下载了包含Eclipse 项目的源代码文件后,我们可以把它导入到当前的Eclipse 工作区然后编辑和查看.点击菜单File > Import,然后在弹出的Import 对话框中 ...

  2. java隐士类型转换和强制类型转换

    ,byte和short型在计算时会自动转换为int型计算,结果也是int 型.所以a1*a2的结果是int 型的. byte+byte=int,低级向高级是隐式类型转换,高级向低级必须强制类型转换,b ...

  3. Spring MVC配置DispatcherServlet的url-pattern

    在配置Spring MVC的核心过滤器DispatcherServlet的url-pattern时是有要求的. <servlet> <servlet-name>...</ ...

  4. python 细枝末节

    1. print  自动换行 看区别 >>> for i in range(4): ... print i ... 0 1 2 3 >>> for i in ran ...

  5. hadoop安装配置——伪分布模式

    1. 安装 这里以安装hadoop-0.20.2为例 先安装java,参考这个 去着下载hadoop 解压 2. 配置 修改环境变量 vim ~/.bashrc export HADOOP_HOME= ...

  6. PowerDesigner中name和code取消自动关联

    PowerDesigner中,如果修改了某个字段的name,其code也跟着修改,如果想取消,可以如下操作 解决方法如下: 1.选择Tools->GeneralOptions...菜单,出现Ge ...

  7. 《Java编程那点事儿》读书笔记(三)——static,this,抽象类,接口和包

    1. static 1)静态变量:Java虚拟机为静态变量开辟单独的存储空间,所以所有的对象内部的静态变量在内存中都指向同一个地址,那么不管哪个对象改变这个成员变量,所有对象中该成员变量的值都发生变化 ...

  8. HDFS的体系结构和操作

    1.对hdfs操作的命令格式是hadoop fs 1.1 -ls <path> 表示对hdfs下一级目录的查看 1.2 -lsr <path> 表示对hdfs目录的递归查看 1 ...

  9. HibernateTools的使用

    1. 到 Hibernate.org官网上 下载最新版的 Hibernate Tools,我用的是 HibernateTools-3.2.4.GA版 2. 将 下载下来的压缩包解压缩,里面会有 plu ...

  10. javascirpt历史澄清误解基本概念特点编程语言web2.0网页javascript - javascirpt知识大全

    目录1历史 2澄清误解 3基本概念 4特点 5与Java的不同 6开发工具 历史 大概在1992年,一家称作Nombas的公司开始开发一种叫做C减减(C-minus-minus,简称Cmm)的嵌入式脚 ...