Hamburgers

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u 

 

Description

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

Output

Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.

Sample Input

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<bits/stdc++.h>
using namespace std;
const int maxn = 110;
typedef long long ll;
char H[maxn];
ll B,S,C;
ll nb,nc,ns;
ll pb,ps,pc;
ll sum1;
ll Start,End; bool check(ll Mid)
{
ll sum = 0;
ll v1,v2,v3;
v1 = (Mid*B - nb)*pb;
v2 = (Mid*S - ns)*ps;
v3 = (Mid*C - nc)*pc;
if(v1 > 0)
sum += v1;
if(v2 > 0)
sum += v2;
if(v3 > 0)
sum += v3;
if(sum > sum1)
return false;
else
return true;
} void get_Start()
{
ll Min = 0x7f7f7f7f;
if(B != 0 && nb / B < Min)
Min = nb / B;
if(S != 0 && ns / S < Min)
Min = ns / S;
if(C != 0 && nc / C < Min)
Min = nc / C;
Start = Min;
}
void get_End()
{
ll sum = 0;
sum = sum + sum1 + nb*pb + ns*ps + nc*pc;
End = sum / (B*pb + S*ps + C*pc);
} void div()
{
ll Mid;
while(1)
{
Mid = (Start + End) / 2;
if(!check(Mid))
End = Mid - 1;
else
Start = Mid + 1;
if(check(Mid) && !check(Mid+1))
break;
}
printf("%lld\n",Mid);
}
int main()
{
while(scanf("%s",H)!=EOF)
{
scanf("%lld%lld%lld%lld%lld%lld%lld",&nb,&ns,&nc,&pb,&ps,&pc,&sum1);
B = S = C = 0;
int len = strlen(H);
for(int i=0; i<len; i++)
{
if(H[i] == 'B')
B++;
else if(H[i] == 'S')
S++;
else if(H[i] == 'C')
C++;
}
get_Start();
get_End();
if(Start == 0 && End == 0)
{
printf("0\n");
continue;
}
div();
}
}

二分法:CF371C-Hamburgers(二分法+字符串的处理)的更多相关文章

  1. I - Beautiful People ZOJ - 2319 (二分法)

    The most prestigious sports club in one city has exactly N members. Each of its members is strong an ...

  2. Python基础之递归函数与二分法

    一.递归函数 定义: 在函数内部,可以调用其他函数.如果一个函数在内部调用自身本身,这个函数就是递归函数. 我们来举个例子吧,比如:有个人问“egon”年龄,他说比“小大”大5岁,“小大”又说比“小保 ...

  3. python 内置函数(二) 进阶函数 递归内容及二分法查找 知识点

    1,lambda:  匿名函数 2.sorgted()  排序函数 3,filter()   过滤函数 筛选 4,map()  映射函数 5.递归 6.二分法 一. 匿名函数: lambda lamb ...

  4. Java实现二分法排序

    二分法:(二分法不是只能做数组,这里的数组只是为了举例) 在给出的有序排列的数组中,把目标值和数组中间值进行比较,如果相等,则返回中间值下标,如果目标值小于中间值,就从数组的前半段再次执行二分法查找, ...

  5. iOS 排序算法总结、二分法查找

    1.插入排序 在要排序的一组数中,假设前面(n-1) [n>=2] 个数已经是排好顺序的,现在要把第n个数插到前面的有序数中,使得这n个数也是排好顺序的.如此反复循环,直到全部排好顺序. 直接插 ...

  6. 33,Leetcode 搜索旋转排序数组-C++ 递归二分法

    题目描述 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] ). 搜索一个给定的目标值,如果数组中存在这 ...

  7. Leetcode 69. Sqrt(x)及其扩展(有/无精度、二分法、牛顿法)详解

    Leetcode 69. Sqrt(x) Easy https://leetcode.com/problems/sqrtx/ Implement int sqrt(int x). Compute an ...

  8. LeetCode刷题模板(1):《我要打10个》之二分法

    Author       :  叨陪鲤 Email         : vip_13031075266@163.com Date          : 2021.01.23 Copyright : 未 ...

  9. Python基础之函数:4、二分法、三元表达式、生成/推导式、匿名函数、内置函数

    目录 一.算法简介之二分法 1.什么是算法 2.算法的应用场景 3.二分法 二.三元表达式 1.简介及用法 三.各种生成式 1.列表生成式 2.字典生成式 3.集合生成式 四.匿名函数 五.常见内置函 ...

随机推荐

  1. Docker | 第四章:Dockerfile简单介绍及使用

    前言 前一章节,介绍了Docker常用的命令.在基本使用上,熟悉这些常用的命令基本上就够了.但在一些场景下,比如在部署SpringBoot应用时,通常我们都是打成Jar包,然后利用java命令进行运行 ...

  2. spring boot注入error,Consider defining a bean of type 'xxx' in your configuration问题解决方案

    经常出现这问题一定是非spring生态圈的@标签 没被spring引入,如mybatis等 因为在默认情况下只能扫描与控制器在同一个包下以及其子包下的@Component注解,以及能将指定注解的类自动 ...

  3. css中 repeat-x 的简单用法

    问repeat-x 00 中: 0 0 是 什么意思,如果改为0 -50呢,不写话默认是什么(不写话和0 0  的效果不一样)- ------<html><head><s ...

  4. using System.Web.Script.Serialization

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programming Langu ...

  5. 在sublime text3下,用快捷键把文件打开到浏览器中

    使用背景 在编辑html或者js文件的时候,是否想在浏览器中预览一下, 你的步骤可能是这样的: 找到编辑文件的位置, 右键使用某一浏览器打开.如果是这样,你就out了, 因为在sublime中有更加简 ...

  6. 【踩坑】遇到 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 报错

    今天在重做 iblog 客户端时,测试接口情况,发现了 org.apache.ibatis.binding.BindingException: Invalid bound statement (not ...

  7. yum 和 rpm安装mysql彻底删除

    1.yum方式安装的MySQL $ yum remove mysql mysql-server mysql-libs compat-mysql51 $ rm -rf /var/lib/mysq $ r ...

  8. Servlet的生命周期以及线程安全问题

    一:Servlet生命周期图,以及注意事项 二:代码演示 LifeCycleServlet.java package cn.woo.servlet; import java.io.IOExceptio ...

  9. tcpick

    tcpick 是一款基于文本的嗅探器,能追踪,重组和重排tcp流.

  10. Oracle数据库基础--建表语法+操作

    语法 1.建表 create table 表名( 列名 数据类型, …… ); 2.删除表:drop table 表名; 3.添加列:alter table 表名 add(列名 数据类型); 4.修改 ...