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 andpc 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 nbnsnc (1 ≤ nb, ns, nc ≤ 100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers pbpspc (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, coutstreams 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

二分查找:
(1) 二分 做汉堡包的个数 -〉满足单调性
(2) judge函数满足贪心选择
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <set>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
LL oneprice ;
LL b ,s ,c ,pb ,ps ,pc ,strb ,strs ,strc ,all_money ;
int judge(LL n){
LL sum = n*oneprice ;
LL use_s = n*strs ;
LL use_c = n*strc ;
LL use_b = n*strb ;
sum -= pb*Min(b,use_b) ;
sum -= ps*Min(s,use_s) ;
sum -= pc*Min(c,use_c) ;
return all_money >= sum ;
} LL calc(){
LL L ,R ,mid , ans = ;
L = ;
R = all_money/oneprice + ;
while(L <= R){
mid = (L + R) >> ;
if(judge(mid)){
ans = mid ;
L = mid + ;
}
else
R = mid - ;
}
return ans ;
}
int main(){
string str ;
int i ;
while(cin>>str){
cin>>b>>s>>c>>pb>>ps>>pc ;
cin>>all_money ;
strb = strc = strs = ;
for(i = ; i < str.length() ; i++){
if(str[i] == 'B')
strb++ ;
else if(str[i] == 'S')
strs++ ;
else
strc++ ;
}
oneprice = strb*pb + strc*pc + strs*ps ;
cout<<calc()<<endl ;
}
return ;
}

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

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

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

  2. Codeforces Round #218 (Div. 2)

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

  3. Codeforces Round #218 (Div. 2) C题

    C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. Codeforces Round #218 (Div. 2) D. Vessels

    D. Vessels time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  5. Codeforces Round #218 (Div. 2) B. Fox Dividing Cheese

    B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #218 (Div. 2) (线段树区间处理)

    A,B大水题,不过B题逗比了题意没理解清楚,讲的太不清楚了感觉= =还是英语弱,白白错了两发. C: 二分答案判断是否可行,也逗比了下...二分的上界开太大导致爆long long了...   D: ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. ettercap ARP dns 欺骗

    1.arp 这个简单,太熟了.略过1     2.dns   根据arp欺骗的步骤. 多了个etter.dns文件 找到它:locate etter.dns 进入后添加dns正向解析     启动,选 ...

  2. HTML5显示地图例子

    html 5获取GPS位置,Google地图显示 场景: JQuery Mobile 代码片段: <script type="text/javascript"> $(' ...

  3. bzoj4561: [JLoi2016]圆的异或并

    Description 在平面直角坐标系中给定N个圆.已知这些圆两两没有交点,即两圆的关系只存在相离和包含.求这些圆的异或面 积并.异或面积并为:当一片区域在奇数个圆内则计算其面积,当一片区域在偶数个 ...

  4. 一款灵活好用的日历控件Kalendae

    Kalendae是一款纯js不依赖任何js库的日历控件,可以轻松实现显示月份数量,当前选中多个日期,并可以按照周等你想要的格式去定制选中项. 下载地址:GitHub/Kalendae 第一步:Kale ...

  5. [Freescale]E9学习笔记-LTIB安装配置

    转自:http://blog.csdn.net/girlkoo/article/details/44535979 LTIB: Linux Target Image Builder Freescale提 ...

  6. 11个实用的Apache .htaccess配置

    <IfModule mod_rewrite.c>RewriteEngine onRewriteBase /RewriteRule cat_([0-9]{1,})_([0-9]{1,})_( ...

  7. Callable和Future

    在并发编程时,一般使用runnable,然后扔给线程池完事,这种情况下不需要线程的结果. 所以run的返回值是void类型. 如果是一个多线程协作程序,比如菲波拉切数列,1,1,2,3,5,8...使 ...

  8. android fragment getActivity()为空的另一个可能

    目前这个方法得到空指针一般来说是因为Activity被销毁导致无法获取,但是开发中又出了一个低级错误导致getActivity为空. 因为我在Fragment的构造函数中调用这个方法了..此时Acti ...

  9. [物理学与PDEs]第4章习题参考解答

    [物理学与PDEs]第4章习题1 反应力学方程组形式的化约 - 动量方程与未燃流体质量平衡方程 [物理学与PDEs]第4章习题2 反应力学方程组形式的化约 - 能量守恒方程 [物理学与PDEs]第4章 ...

  10. android:gravity 和 android:layout_Gravity属性

    LinearLayout有两个非常相似的属性: android:gravity 与android:layout_gravity. 他们的区别在于: android:gravity 属性是对该view中 ...