二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers
/*
题意:一个汉堡制作由字符串得出,自己有一些原材料,还有钱可以去商店购买原材料,问最多能做几个汉堡
二分:二分汉堡个数,判断此时所花费的钱是否在规定以内
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std; typedef long long ll;
const int MAXN = 1e2 + ;
const int INF = 0x3f3f3f3f;
char ham[MAXN];
ll nb, ns, nc;
ll pb, ps, pc;
ll b, s, c;
ll m; bool check(ll x) {
ll cost = ;
if (b * x > nb) cost += (b * x - nb) * pb;
if (s * x > ns) cost += (s * x - ns) * ps;
if (c * x > nc) cost += (c * x - nc) * pc;
return cost <= m;
} int main(void) { //Codeforces Round #218 (Div. 2) C. Hamburgers
scanf ("%s", &ham);
scanf ("%I64d%I64d%I64d", &nb, &ns, &nc);
scanf ("%I64d%I64d%I64d", &pb, &ps, &pc);
scanf ("%I64d", &m);
b = s = c = ;
for (int i=; ham[i]; ++i) {
if (ham[i] == 'B') b++;
else if (ham[i] == 'S') s++;
else c++;
}
ll l = , r = 1e13;
while (l + < r) {
ll mid = (l + r) >> ;
if (check (mid)) l = mid;
else r = mid;
}
printf ("%I64d\n", l); return ;
}
二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers的更多相关文章
- Codeforces Round #218 (Div. 2) C. Hamburgers
C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 二分搜索 Codeforces Round #299 (Div. 2) C. Tavas and Karafs
题目传送门 /* 题意:给定一个数列,求最大的r使得[l,r]的数字能在t次全变为0,每一次可以在m的长度内减1 二分搜索:搜索r,求出sum <= t * m的最大的r 详细解释:http:/ ...
- Codeforces Round #218 (Div. 2)
500pt, 题目链接:http://codeforces.com/problemset/problem/371/A 分析:k-periodic说明每一段长度为k,整个数组被分成这样长度为k的片段,要 ...
- Codeforces Round #218 (Div. 2) C题
C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #218 (Div. 2) D. Vessels
D. Vessels time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #218 (Div. 2) B. Fox Dividing Cheese
B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #218 (Div. 2) (线段树区间处理)
A,B大水题,不过B题逗比了题意没理解清楚,讲的太不清楚了感觉= =还是英语弱,白白错了两发. C: 二分答案判断是否可行,也逗比了下...二分的上界开太大导致爆long long了... D: ...
- Codeforces Round #404 (Div. 2) C 二分查找
Codeforces Round #404 (Div. 2) 题意:对于 n and m (1 ≤ n, m ≤ 10^18) 找到 1) [n<= m] cout<<n; 2) ...
- 刷题记录:Codeforces Round #725 (Div. 3)
Codeforces Round #725 (Div. 3) 20210704.网址:https://codeforces.com/contest/1538. 感觉这个比上一个要难. A 有一个n个数 ...
随机推荐
- 【NOIP2017练习】鏖战字符串(斜率优化DP)
题意: 在决胜局中,Abwad决定和nbc鏖战字符串,比的是谁能更快地将一个“量子态的字符串”删除.“量子态的字符串”的每个字符都有一个删除难度dif[i].“量子态的字符串”非常顽固,只能先分割成若 ...
- Object-C 打开工程,选择模拟起时,提示"no scheme"
错误提示,如下图: 解决思路:
- HTML5学习之语义化标签
一.为什么HTML5要引入新语义标签 在HTML5出现之前,我们一般采用DIV+CSS布局我们的页面.但是这样的布局方式不仅使我们的文档结构不够清晰,而且不利于搜索引擎爬虫对我们页面的爬取.为了解决上 ...
- [bzoj3513][MUTC2013]idiots_FFT
idiots bzoj-3513 MUTC-2013 题目大意:给定$n$根木棍,问随机选择三根能构成三角形的概率. 注释:$1\le n\le 3\cdot 10^5$,$1\le a_i\le 1 ...
- Creating A Simple Web Server With Golang
原文:https://tutorialedge.net/post/golang/creating-simple-web-server-with-golang/ -------------------- ...
- 使用RoboCopy 命令[转载]
经常进行文件管理操作的朋友们,不满意于Windows系统内置的复制功能,因为它太龟速了.于是大家就使用FastCopy.TeraCopy之类的软件来加速复制,但是你是否知道Windows 7已经内置快 ...
- CSS3实现各种格子纹理效果
<!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/h ...
- A. Polo the Penguin and Strings
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- DMA32映射问题
近期在调试PCIe的行情加速卡的驱动.当中使用DMA在CPU和FPGA间数据传输. 最開始使用的是低16M的DMA ZONE的内存,用slab分配器的kmalloc分配获取.但因为最新的需求,须要使用 ...
- jQuery -> 获取指定上下文中的DOM元素
jQuery函数的第二个參数能够指定DOM元素的搜索范围. 第二个參数可分为下面类型 DOM reference jQuery wrapper document 代码演示样例 <!DOCTYPE ...