二分法:CF371C-Hamburgers(二分法+字符串的处理)
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(二分法+字符串的处理)的更多相关文章
- I - Beautiful People ZOJ - 2319 (二分法)
The most prestigious sports club in one city has exactly N members. Each of its members is strong an ...
- Python基础之递归函数与二分法
一.递归函数 定义: 在函数内部,可以调用其他函数.如果一个函数在内部调用自身本身,这个函数就是递归函数. 我们来举个例子吧,比如:有个人问“egon”年龄,他说比“小大”大5岁,“小大”又说比“小保 ...
- python 内置函数(二) 进阶函数 递归内容及二分法查找 知识点
1,lambda: 匿名函数 2.sorgted() 排序函数 3,filter() 过滤函数 筛选 4,map() 映射函数 5.递归 6.二分法 一. 匿名函数: lambda lamb ...
- Java实现二分法排序
二分法:(二分法不是只能做数组,这里的数组只是为了举例) 在给出的有序排列的数组中,把目标值和数组中间值进行比较,如果相等,则返回中间值下标,如果目标值小于中间值,就从数组的前半段再次执行二分法查找, ...
- iOS 排序算法总结、二分法查找
1.插入排序 在要排序的一组数中,假设前面(n-1) [n>=2] 个数已经是排好顺序的,现在要把第n个数插到前面的有序数中,使得这n个数也是排好顺序的.如此反复循环,直到全部排好顺序. 直接插 ...
- 33,Leetcode 搜索旋转排序数组-C++ 递归二分法
题目描述 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] ). 搜索一个给定的目标值,如果数组中存在这 ...
- Leetcode 69. Sqrt(x)及其扩展(有/无精度、二分法、牛顿法)详解
Leetcode 69. Sqrt(x) Easy https://leetcode.com/problems/sqrtx/ Implement int sqrt(int x). Compute an ...
- LeetCode刷题模板(1):《我要打10个》之二分法
Author : 叨陪鲤 Email : vip_13031075266@163.com Date : 2021.01.23 Copyright : 未 ...
- Python基础之函数:4、二分法、三元表达式、生成/推导式、匿名函数、内置函数
目录 一.算法简介之二分法 1.什么是算法 2.算法的应用场景 3.二分法 二.三元表达式 1.简介及用法 三.各种生成式 1.列表生成式 2.字典生成式 3.集合生成式 四.匿名函数 五.常见内置函 ...
随机推荐
- SpringBoot | 第零章:前言
缘起 前段时间公司领导叫编写一两课关于springboot的基础知识培训课程,说实话,也是今年年初才开始接触了SpringBoot这个脚手架,使用了之后才发现打开了一个新世界.再之后也没有一些系统的学 ...
- CentOS6.5 环境安装配置
一.GO环境配置 1.运行命令进入/usr/local/src目录:cd /usr/local/src 2.下载安装包:运行wget --no-check-certificate https://st ...
- 完美解决Android在listview添加checkbox实现单选多选操作问题
在Android某些开发需求当中,有时候需要在listveiw中加入checkbox实现单选,多选操作.表面上看上去只是改变checkbox那么简单,然而实际开发中,实现起来并不是那么得心应手.尤其当 ...
- nginx学习书籍推荐
最好的书是源码 深入理解NGINX" 陶辉著 <实战Nginx...>张宴 <深入理解Nginx:模块开发与架构解析> nginx开发从入门到精通 Nginx HTT ...
- LeetCode Move Zeroes (简单题)
题意: 给定一个整型数组nums,要求将其中所有的0移动到末尾,并维护所有非0整数的相对位置不变. 思路: 扫一遍,两个指针维护0与非0的交界,将非0的数向前赋值就行了. C++ class Solu ...
- Java中的字符串问题
本文章分为三个部分: 1.创建字符串对象的两种方式以及它们的存储方式 2.String a = new String("a")创建了几个对象的问题 3.字符串小例子 ------- ...
- Python常见编程规范总结
Pythonic定义 Python最常用的编码风格还是PEP8,详见:http://jython.cn/dev/peps/pep-0008/ Pythonic确实很难定义,先简单引用下<Pyth ...
- vuejs组件的重要选项
new Vue({ el:'#demo', data:{ message:'Hello vue.js!' } }) 我们看到这个括号里面包含了很多中间的选项,小括号里面其实是一些参数,这些参数指定了实 ...
- 欠采样(undersampling)和过采样(oversampling)会对模型带来怎样的影响
项目中出现了二分类数据不平横问题,研究总结下对于类别不平横问题的处理经验: 为什么类别不平横会影响模型的输出? 许多模型的输出类别是基于阈值的,例如逻辑回归中小于0.5的为反例,大于则为正例.在数据不 ...
- python_43_移动文件指针补充
#移动文件指针补充 ''' 文件对象.seek((offset,where)) offset:移动的偏移量,单位为字节.等于正数时向文件尾方向移动,等于负数时向文件头方向移动文件指针 where:指针 ...