二分法: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.集合生成式 四.匿名函数 五.常见内置函 ...
随机推荐
- Ubuntu安装LAMP环境(PHP5.6) 以及下载安装phpmyadmin
参考路径: http://blog.nciaer.com/?p=133 修改apache(2.4.18)的web路径时, 需要将 /etc/apache2/sites-available/000def ...
- MVC中 Remote的用法
一.web.config加入 <appSettings> <add key="ClientValidationEnabled" value="t ...
- java-类的定义和用法
1.类的定义 public class Human{ }//每个源文件必须也只能有一个public类 class boy{ }//可以定义多个class类 class girl{ } 上面的类定义好后 ...
- Python之简易计算器
思路:学会运用正则表达式把需要先进行计算的匹配出来,然后再一步步的去算,把先算出来的值替换原来的值,再进一步的把++,--等号变成我们正常的数学上的符号,然后再进行一步步的替换,最终把带括号的都计算出 ...
- iOS - 协议实现的例子
在实际开发中,协议的应用非常广泛,以下是实际应用的例子. 1.协议的定义: myProtocolDelegate.h // // myProtocolDelegate.h // zlwPlayerAp ...
- 开发Maven插件
Mojo: Maven plain Old Java Object 1.插件命名规则:maven-<yourplugin>-plugin是Maven的保留字段,不允许使用,我们可以用< ...
- SQL Server(第二章) 字符串函数、日期时间函数、转换函数
--1.CONCAT 函数:字符串连接(支持sql server2012 SQL规则 如果与NULL连接返回NILL) SELECT empid,CONCAT(firstname,lastname) ...
- 创建1M-1T的虚拟磁盘(内存盘)——使用破解版 Primo Ramdisk Server Edition v5.6.0
破解版 Primo Ramdisk Server Edition v5.6.0下载: https://pan.lanzou.com/i0sgcne 步骤: 下载并解压后安装“Primo.Ramdisk ...
- 【洛谷2152】[SDOI2009] SuperGCD(Python好题)
点此看题面 大致题意: 给你两个长度\(\le10000\)的正整数,让你求它们的\(gcd\). Python 高精请绕道. 这题的正解应该是Python. 对于这种高精题,肯定是Python最方 ...
- 文件系统inodes使用率过高问题处理
运维过程中经常碰见文件系统inodes使用率过高导致文件系统不可写的问题,常见场景如下 .Oracle产生的审计文件,特别是DG备库或者审计设置为OS时 .crontab产生大量邮件,导致/var/s ...