CodeForces 371C Hamburgers
B题又耽误时间了。。。人太挫了。。。。
1 second
256 megabytes
standard input
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.
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 %I64dspecifier.
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
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string> using namespace std; int main()
{
long long int B=0,S=0,C=0,r,nb,ns,nc,pb,ps,pc,ans=0;
string s;
cin>>s;
for(int i=0;i<s.size();i++)
{
if(s[i]=='B') B++;
if(s[i]=='C') C++;
if(s[i]=='S') S++;
}
int tx=0,t1=0;
tx=(B>0)+(C>0)+(S>0);
cin>>nb>>ns>>nc>>pb>>ps>>pc>>r;
int prise=B*pb+C*pc+S*ps;
///一次做成一个
bool flag=true;
while(r>0)
{
if((nb||nc||ns)&&flag)
{
bool flagB=false,flagC=false,flagS=false;
if(nb>=B) nb-=B,flagB=true;
else
{
int buy=B-nb; nb=0;
if(r>=buy*pb) r-=buy*pb,flagB=true;
else break;
} if(nc>=C) nc-=C,flagC=true;
else
{
int buy=C-nc; nc=0;
if(r>=buy*pc) r-=buy*pc,flagC=true;
else break;
} if(ns>=S) ns-=S,flagS=true;
else
{
int buy=S-ns; ns=0;
if(r>=buy*ps) r-=buy*ps,flagS=true;
else break;
}
t1=(nb==0)+(nc==0)+(ns==0);
if(t1==tx) flag=false;
if(flagB&&flagC&&flagS) ans++;
else break;
}
else
{
ans+=r/prise;
break;
}
}
cout<<ans<<endl;
return 0;
}
CodeForces 371C Hamburgers的更多相关文章
- Codeforces 371C Hamburgers (二分答案)
题目链接 Hamburgers 二分答案,贪心判断即可. #include <bits/stdc++.h> using namespace std; #define REP(i,n) fo ...
- CodeForces 371C Hamburgers(经典)【二分答案】
<题目链接> 题目大意: 给以一段字符串,其中只包含"BSC"这三个字符,现在有一定量免费的'B','S','C‘,然后如果想再买这三个字符,就要付出相应的价格.现在总 ...
- codeforces 371c
#include<stdio.h> int main() { char s[200]; __int64 r,nb,ns,nc,pb,ps,pc,i,sum,tob,tos,toc; wh ...
- C++练习 | 二分练习
Codeforces 371C : Hamburgers #include<bits/stdc++.h> using namespace std; char B='B',S='S',C=' ...
- 二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers
题目传送门 /* 题意:一个汉堡制作由字符串得出,自己有一些原材料,还有钱可以去商店购买原材料,问最多能做几个汉堡 二分:二分汉堡个数,判断此时所花费的钱是否在规定以内 */ #include < ...
- Codeforces Round #218 (Div. 2) C. Hamburgers
C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Hamburgers
Hamburgers http://codeforces.com/problemset/problem/371/C time limit per test 1 second memory limit ...
- C. Hamburgers
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own han ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- 模式匹配KMP
字符串朴素模式匹配算法的2种实现: //1.朴素的模式匹配算法,用while实现 int StrStr_While(const char* pStr, const char* pSub, int* p ...
- [Andriod官方API指南]连接之蓝牙
Bluetooth —— 蓝牙 The Android platform includes support for the Bluetooth network stack, which allows ...
- BZOJ 4143: [AMPPZ2014]The Lawyer( sort )
水题... 排序搞出每天的会议有哪些, 然后再按照会议的开始时间和结束时间排序, 最晚开始的和最早结束的会议不是同一场而且最晚开始的时间>最早结束的会议就有可能方案 -------------- ...
- django局域网建一个网站
之前总是运行的python manage.py runserver,用默认的在本机访问的127.0.0.1:8000,如果跟几个同学一起去开发一个网站来玩玩的话,可以这样: python manage ...
- Git 将本次修改追加在上一次修改上面
Git 将本次修改追加在上一次修改上面 git add . git commit --amend 之后就是进入日志提交页面 确保change-Id那条记录出现在最后一行,如: zh-->en 修 ...
- perl 面向对象 new方法
[root@wx03 test]# cat Scan.pm package Scan; sub new{ my $class = shift; my $self={ 'a'=>11, 'b'=& ...
- 7款Linux下阅读PDF的阅读器。
5款Linux下阅读PDF的阅读器.1. Mupdf:link 2. Adobe Reader:link 3. Foxit Reader:link 4.Evince:link 5. Okular:li ...
- 京东金融集团BD部门招聘 BD经理
新标签页http://74.55.154.136/ 互联网招聘_cnBeta.COM 北京 / 全职 / 20k-30k / 经验3-5年 / 本科及以上 / 1天前发布 职位诱惑 : 五险一金 职位 ...
- php 上传文件代码
通过 PHP,能够把文件上传到server.里面加入一些图片的推断,假设不加推断文件的类型就能够上传随意格式的文件. 为了站点的安全,肯定不让上传php文件,假设有人进入你的后台,上传了一个php文件 ...
- matlab三维画图
matlab三维画图主要有三个命令:plot3命令.mesh命令和surf命令. plot3 plot3是三维画图的基本函数,绘制的是最为主要的3D曲线图,最主要的调用格式是: plot3(X,Y,Z ...