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‘,然后如果想再买这三个字符,就要付出相应的价格.现在总 ...
随机推荐
- thrift编译java的问题-(安装thrift0.8.0成功-编译mapkeeper.java成功)
上一次帖子说了thrift编译java出现错误,由于只用到cpp版的,就将此略过.但是老版本的ycsb不是很好用,于是决定以locall的方式编译mapkeeper供最新版ycsb使用.目前根据 ht ...
- 转,如果linux不能用yum安装asterisk时,可以库参照以下办法添加asterisk仓库
LinuxCentOSRedHat Installing a binary distribution of Asterisk makes it easier to maintain your syst ...
- BZOJ2006:超级钢琴(ST表+堆求前K大区间和)
Description 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以弹奏出n个音符,编号为1至n.第i个音符的美妙度 ...
- LeetCode 889. Construct Binary Tree from Preorder and Postorder Traversal
原题链接在这里:https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/ 题 ...
- vue-router 获得上一级路由以及返回上一级路由的方法
if (this.$store.state.previousRouter.name) { this.$router.push({name: this.$store.state.previousRout ...
- vuex本地存储
vuex与localstorage 区别:vuex数据存储的内存,localstorage的数据存储在本地 应用场景:vuex用于组件之间的传值,localstorage用于不同页面之间的传值 永久性 ...
- bzoj5102
$贪心$ $按左端点排序.$ $当我们钦定了最右的左端点,那么自然希望右端点尽量靠右$ $考虑之前的区间,那么我们相当于选之前的区间中第k大的右端点$ $堆维护一下就可以了,每次把新的元素放进堆,如果 ...
- 《Java多线程编程核心技术》读后感(一)
1.继承Thread package First; public class MyThread extends Thread { public void run() { super.run(); Sy ...
- Apache CXF简介
Apache CXF是一个开源的,全功能的,容易使用的Web服务框架.CXF是由Celtix和XFire合并,在Apache软件基金会共同完成的.CXF的名字来源于"Celtix" ...
- 利用jstack定位典型性能问题实例
此文已由作者朱笑天授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 问题的起因是笔者在一轮性能测试的中,发现某协议的响应时间很长,去观察哨兵监控里的javamethod监控可以 ...