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.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- HttpComponents 也就是以前的httpclient项目
HttpComponents 也就是以前的httpclient项目,可以用来提供高效的.最新的.功能丰富的支持 HTTP 协议的客户端/服务器编程工具包,并且它支持 HTTP 协议最新的版本和建议.不 ...
- line-height具体解释
章:浏览器与Hack].7.3.5 应用:单行文字在垂直方向居中在网页设计中,往往为了突出标题而加入背景图案.如图7-31所看到的. watermark/2/text/aHR0cDovL2Jsb2cu ...
- [Unity 3D] Unity 3D 性能优化 (一)
听到过很多用Unity 3D开发游戏的程序员抱怨引擎效率太低,资源占用太高,包括我自己在以往项目的开发中也头疼过.最近终于有了空闲,可以仔细的研究一下该如何优化Unity 3D下的游戏性能.其实国外有 ...
- VTK中国文字显示和简单的医疗图像浏览软件
使用VTK做一个简单的医学图像浏览软件(在http://blog.csdn.net/www_doling_net/article/details/8668870这篇博文的基础上改的),支持标准的医学图 ...
- js 中 字符串的转换
JS 中将 number 转换为 string 我们比较熟悉,直接用toString() 的方法就可以了:那么将 string 转换成为 number 都有些什么方法呢?如下便简单的列举了一些,以便记 ...
- Python 第二篇:python字符串、列表和字典的基本操作方法
本文基于python 3.5.1 python常见的数据类型有字串.列表.元组.字典等,本文将详细介绍每一种数据类型的操作方法. 一:str字串的操作方法: 1.capitalize()--> ...
- xmlns:android="http://schemas.android.com/apk/res/android的作用是
xmlns:android="http://schemas.android.com/apk/res/android的作用是 这个是xml的命名空间,有了他,你就可以alt+/作为提示,提示你 ...
- Esper学习之五:EPL语法(一)
上篇说到了Esper的Context,要是不了解的同学请参看<Esper学习之四:Context>,看过的同学如果还是不理解的话可以给我评论,我将会尽可能的解答.之前有些同学问我Conte ...
- 在Web Api中快速实现JSonp
本文翻译自:http://www.codeproject.com/Tips/631685/JSONP-in-ASP-NET-Web-API-Quick-Get-Started Concept: 同源策 ...
- WS_EX_TOOLWINDOW 属性的陷阱
WS_EX_TOOLWINDOW,带有这个属性的窗口有以下特点: 1. 不在任务栏显示. 2. 不显示在Alt+Tab的切换列表中. 3. 在任务管理器的窗口管理Tab中不显示. 我们可能会出于某种目 ...