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. hdu 4223

    暴力: Problem : ( Dynamic Programming? ) Judge Status : Accepted RunId : Language : C++ Author : yudun ...

  2. Shell脚本基础I

    1.Linux shell类型 /bin/sh--已经被/bin/bash所取代 /bin/bash--就是Linux预设的shell /bin/ksh--由AT&T Bell lab发展出来 ...

  3. SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-001-使用Hibernate(@Inject、@EnableTransactionManagement、@Repository、PersistenceExceptionTranslationPostProcessor)

    一.结构 二.Repository层 1. package spittr.db; import java.util.List; import spittr.domain.Spitter; /** * ...

  4. [cocoapods]安装cocoapods

    如果你的电脑已经安装过cocoapods了,但是不知道怎么用,请直接跳转到第8步 在安装之前,我们先来了解什么是cocoapods 当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONK ...

  5. Android从零单排之自动跟新

    自动更新原理 当我们发布我们的应用程序的时候,肯定会想到后续版本的更新,那么该怎么对我们的程序进行更新呢? 更新APK的原理实际上就是比较程序中的AndroidManifest.xml中的versio ...

  6. skip-name-resolv

    skip-name-resolve skip-name-resolve 简单解释 MySQL server received a request from you to allow you to co ...

  7. WPF如何用TreeView制作好友列表、播放列表

    WPF如何用TreeView制作好友列表.播放列表 前言 TreeView这个控件对于我来说是用得比较多的,以前做的小聊天软件(好友列表).音乐播放器(播放列表).类库展示器(树形类结构)等都用的是T ...

  8. js判断是移动端还是pc端

    运行页面的时候,执行到js会判断来自于移动端还是pc端,如果是移动端则跳转制定链接地址,这样在手机端会有额外的不必要浪费的加载时间 var browser={ versions:function(){ ...

  9. 《c程序设计语言》读书笔记--统计换行数,空格数,tab数

    #include <stdio.h> int main() { int spa = 0,lin = 0,tab = 0; int c; /* spa代表空格个数,tab代表制表符个数,li ...

  10. hadoop hadoop-0.20.2-cdh3u4升级

    [hadoop@lab02 ~]$ uname -aLinux lab02 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 2010 x86_64 x86_ ...