C. Hamburgers
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.
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.
Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.
BBBSSC
6 4 1
1 2 3
4
2
BBC
1 10 1
1 10 1
21
7
BSC
1 1 1
1 1 3
1000000000000
200000000001
http://codeforces.com/problemset/problem/371/C
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<math.h>
using namespace std;
int B,S,C;//一个汉堡需要的
int nb,nc,ns;//已有的
int pb,pc,ps;//单价
long long money;
long long l,r,mid;
bool check(long long mid)
{
long long need=;
if(mid*B>nb) need+= (mid*B-nb)*pb;
if(mid*S>ns) need += (mid*S-ns)*ps;
if(mid*C>nc) need += (mid*C-nc)*pc;
return need<=money;
}
int main()
{
char a[];int len;
cin>>a+;len=strlen(a+);
cin>>nb>>ns>>nc;
cin>>pb>>ps>>pc;
cin>>money;
for(int i=;i<=len;i++)
{
if(a[i]=='B') B++;else
if (a[i]=='C') C++;else
if(a[i]=='S') S++;
}
l=0;r=money+max(max(nb,nc),ns);//这里要考虑最大值,原来的,加钱数。
二分时,一定要注意左右边界!!!!!
while(l<=r)//二分答案,能做出的汉堡数
{
mid=(l+r)>>;
if(check(mid))
l=mid+;
else r=mid-;
}
cout<<r;
return ;
}
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<math.h>
using namespace std;
int B,S,C;//一个汉堡需要的
int nb,nc,ns;//已有的
int pb,pc,ps;//单价
long long money;
long long ans;
long long need=;
bool check(int mid)
{
need=;
if(mid*B>nb&&B) need+= (mid*B-nb)*pb; if(mid*S>ns&&S) need += (mid*S-ns)*ps; if(mid*C>nc&&C) need += (mid*C-nc)*pc; return need<=money;
}
int main()
{
char a[];int len;
cin>>a+;len=strlen(a+);
cin>>nb>>ns>>nc;
cin>>pb>>ps>>pc;
cin>>money;
for(int i=;i<=len;i++)
{
if(a[i]=='B') B++;else
if (a[i]=='C') C++;else
if(a[i]=='S') S++;
}
while(check())
{
nb=nc=ns=;
ans+=;
money-=need;
}
while(check())
{
nb=nc=ns=;
ans+=;
money-=need;
}
while(check())
{
nb=nc=ns=;
ans+=;
money-=need;
}
while(check())
{
if(B>=nb) nb=0;else nb-=B;
if(S>=ns) ns=0;else ns-=S;
if(C>=nc) nc=0;else nc-=C;//这个处理就花费了我大部分时间,本来是写在check里的但是,对剩余材料的处理,必须是check==1时才能进行。所以要写在while里
ans+=;
money-=need;
}
cout<<ans;
return ;
} //当然这并不是真正的贪心,再说吧。
C. Hamburgers的更多相关文章
- Codeforces Round #218 (Div. 2) C. Hamburgers
C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CodeForces 371C Hamburgers
B题又耽误时间了...人太挫了.... C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes i ...
- B - Hamburgers
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own han ...
- Hamburgers
Hamburgers http://codeforces.com/problemset/problem/371/C time limit per test 1 second memory limit ...
- Codeforces 371C Hamburgers (二分答案)
题目链接 Hamburgers 二分答案,贪心判断即可. #include <bits/stdc++.h> using namespace std; #define REP(i,n) fo ...
- 二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers
题目传送门 /* 题意:一个汉堡制作由字符串得出,自己有一些原材料,还有钱可以去商店购买原材料,问最多能做几个汉堡 二分:二分汉堡个数,判断此时所花费的钱是否在规定以内 */ #include < ...
- H Kuangyeye and hamburgers
链接:https://ac.nowcoder.com/acm/contest/338/H来源:牛客网 题目描述 Kuangyeye is a dalao of the ACM school team ...
- cf C. Hamburgers
http://codeforces.com/contest/371/problem/C 二分枚举最大汉堡包数量就可以. #include <cstdio> #include <cst ...
- CodeForces 371C Hamburgers(经典)【二分答案】
<题目链接> 题目大意: 给以一段字符串,其中只包含"BSC"这三个字符,现在有一定量免费的'B','S','C‘,然后如果想再买这三个字符,就要付出相应的价格.现在总 ...
随机推荐
- 「NOIP2002」「Codevs1099」 字串变换(BFS
1099 字串变换 2002年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知有两个字串 $A$, ...
- eclipse Tomcat 启动报错
如果之前启动都是正常的,更新完后端代码后启动Tomcat报错,又没有错误的日志提示. 尝试先把Tomcat里面的项目删掉,然后点击Tomcat右键,Clean清除缓存,再把项目Add: 重新启动!
- Python下使用Psyco模块优化运行速度
今天介绍下Psyco模块,Psyco模块可以使你的Python程序运行的像C语言一样快.都说Python语言易用易学,但性能上跟一些编译语言(如C语言)比较要差不少,这里可以用C语言和Python语言 ...
- ubuntu16.04 + CUDA 9.0 + opencv3.3 安装
安装前的准备 CUDA 9.0 安装,可以参看Ubuntu16.04 + cuda9.0 + cudnn7.1.4 + tensorflow安装 opencv 3.3.0 下载 ippicv_2017 ...
- js正则匹配字符串
这里我第一时间想到的就是用 js 的search 和 match ,其中最常见的是match: 1. str.search(regexp):search()方法不支持全局搜索,因为会忽略正则表达式参数 ...
- Eigen::aligned_allocator
http://blog.csdn.net/rs_huangzs/article/details/50574141
- app自动化测试工具robotium
robotium基于instramentation框架,可对app白盒黑盒测试,缺点是测试进程和被测进程需要在一个进程中,不能跨应用 白盒测试时,需要app源代码,在eclipse里新建android ...
- 【eclipse插件开发实战】Eclipse插件开发7——插件发布jar包
Eclipse插件开发7--插件发布jar包 最省事的方式就是直接导出jar包,然后放到eclipse的plugins目录下,重启eclipse即可. step1: 对需要打包的插件工程右击→导出(E ...
- 微信小程序开发之真机预览
1:真机预览时上传组件的坑: 当在真机里面使用上传组件,当进入选择相片或者拍照的时候,小程序会进入后台,调用APP onHide()方法,选择完返回小程序是会调用App Onshow()方法,然后调用 ...
- 电商:html样式集合
1. <span class="big" style="text-decoration:line-through;">原价:¥{zlcms:art ...