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. 文件格式PDF

    pdf(Portable Document Format的简称,意为“便携式文档格式”),是由Adobe Systems用于与应用程序.操作系统.硬件无关的方式进行文件交换所发展出的文件格式.PDF文 ...

  2. JVM垃圾回收机制总结(6) :透视Java的GC特性

    1. 使用 System.gc() 可以不管JVM使用的是哪一种垃圾回收的算法,都可以请求 Java的垃圾回收. 在命令行中有一个参数-verbosegc可以查看Java使用的堆内存的情况,它的格式: ...

  3. swift:创建表格UITableView

    用swift创建单元格和用iOS创建单元格形式基本相同,就是语法上有些异样.swift中调用成员方法不再使用[ ]来发送消息,而是使用.成员方法的形式调用成员函数.这种格式非常类似于java中的点成员 ...

  4. 文件相关操作工具类——FileUtils.java

    文件相关操作的工具类,创建文件.删除文件.删除目录.复制.移动文件.获取文件路径.获取目录下文件个数等,满足大多数系统需求. 源码如下:(点击下载 FileUtils.java) import jav ...

  5. pycharm最新注册方法 pycharm最新激活方法 2016pycharm最新注册方法

    激活注册码:点击确认就可以了 43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTczWVlKIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaW ...

  6. 第九篇 ERP实施项目中需求分析及方案设计的通用思路

    顾问实施ERP就好想医生给患者看病抓药,不但具有类似的过程,而且具有其通用的思路. --详见http://bbs.erp100.com/thread-272856-1-1.html 顾问实施ERP就好 ...

  7. 《OD学HBase》20160821

    一.HBase性能调优 1. JVM内存调优 MemStore内存空间,设置合理大小 memstore.flush.size 刷写大小 134217728 = 128M memstore.mslab. ...

  8. hibernate学习笔记4---HQL、通用方法的抽取实现

    一.通用方法的抽取实现 由于hibernate中对增删改查的一切操作都是面向对象的,所以将增删改查抽取成通用方法,以满足不同的表的增删改查操作,简化jdbc代码. 具体例子如下: package cn ...

  9. Oracle数据库之三

    子查询 -- 就是在一个查询中包含多个select语句(一般就2个) select id,first_name,dept_id from s_emp; 想查询和Ben一个部门的员工的id,first_ ...

  10. SQL注入与Java

    前面这篇文章介绍了SQL注入,并且主要就PHP的内容做了实验: http://www.cnblogs.com/charlesblc/p/5987951.html 还有这篇文章对处理方案做了介绍(Pre ...