B题又耽误时间了。。。人太挫了。。。。

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 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.

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, cout streams or the %I64dspecifier.

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

#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的更多相关文章

  1. Codeforces 371C Hamburgers (二分答案)

    题目链接 Hamburgers 二分答案,贪心判断即可. #include <bits/stdc++.h> using namespace std; #define REP(i,n) fo ...

  2. CodeForces 371C Hamburgers(经典)【二分答案】

    <题目链接> 题目大意: 给以一段字符串,其中只包含"BSC"这三个字符,现在有一定量免费的'B','S','C‘,然后如果想再买这三个字符,就要付出相应的价格.现在总 ...

  3. codeforces 371c

    #include<stdio.h> int main() { char s[200]; __int64  r,nb,ns,nc,pb,ps,pc,i,sum,tob,tos,toc; wh ...

  4. C++练习 | 二分练习

    Codeforces 371C : Hamburgers #include<bits/stdc++.h> using namespace std; char B='B',S='S',C=' ...

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

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

  6. Codeforces Round #218 (Div. 2) C. Hamburgers

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

  7. Hamburgers

    Hamburgers http://codeforces.com/problemset/problem/371/C time limit per test 1 second memory limit ...

  8. C. Hamburgers

    Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own han ...

  9. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

随机推荐

  1. bad interpreter: No such file or directory解决

    执行shell脚本时出现bad interpreter: No such file or directory错误, 一般是因为linux无法识别出Windows的DOS格式,此时只需将文件格式转换成u ...

  2. linux下C++开发工具

    就C++开发工具而言,与Windows下微软(VC, VS2005等)一统天下相比,Linux/Unix下C++开发,可谓五花八门,各式各样.Emacs, vi, eclipse, anjuta,kd ...

  3. KINGSO介绍

    kingso_intro - Taocode KINGSO介绍 KINGSO是一种高效的垂直化的搜索引擎,其包含query解析.检索.过滤.统计.排序功能,不包含抓取部分.它对商品搜索做了针对性的优化 ...

  4. [leetcode] Reverse Linked List 分类: leetcode 算法 2015-07-09 18:44 2人阅读 评论(0) 收藏

    反转链表:比较简单的问题,可以遍历也可以递归. # Definition for singly-linked list. class ListNode: def __init__(self, x): ...

  5. java项目打jar包的两种情况

    链接地址:http://jingyan.baidu.com/article/6b97984d8a6ddc1ca2b0bfa0.html 本文介绍一下java项目打jar包时的两种情况各怎么操作   方 ...

  6. 第14周 项目三-OOP版电子词典

    做一个简单的电子词典.在文件dictionary.txt中,保存的是英汉对比的一个词典,词汇量近8000个,英文.中文释义与词性间用'\t'隔开. (1)编程序,由用户输入英文词.显示词性和中文释义. ...

  7. iOS 使用Block实现函数回调

    事实上.iOS中的Block就是C++中的函数指针,实现方式都是一样的,以下贴出一个简单的实践. 首先,创建一个回调的类 BlockStudy.h // // BlockStudy.h // Bloc ...

  8. IT忍者神龟之Oracle DBA经常使用查询吐血列举

    –1. 查询系统全部对象 select owner, object_name, object_type, created, last_ddl_time, timestamp, status from ...

  9. PE文件简单介绍

    PE(Portable Execute)文件是WIN32下可运行文件遵循的数据格式,也是反汇编调试不可缺少的文件,常见的pe文件有.exe和.dll文件.本文主要介绍pe文件的结构和虚拟内存地址转换到 ...

  10. Notepad++中如何设置自动换行以及行宽

    view-->word wrap; setting->preference-->vertical edge settings; Notepad++中如何设置自动换行以及行宽 http ...