二分搜索 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个数 ...
随机推荐
- 【BZOJ2527】Meteors(整体二分)
题意: Byteotian Interstellar Union有N个成员国.现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第1份相邻),第i份上有第Ai个国家的太空站. 这个星球经常会 ...
- SpringMVC之application-context.xml,了解数据库相关配置
上一篇SpringMVC之web.xml让我们了解到配置一个web项目的时候,怎样做基础的DispatcherServlet相关配置.作为SpringMVC上手的第一步.而application-co ...
- Servlet之中文乱码问题【入门版】
请求数据的中文问题 1 post请求提交中文 get请求建议不提交中文(只是也有方法解决) 1.1post request.setCharacterEncoding("utf-8" ...
- easyUI datagrid 前端真分页
前文再续,书接上一回.easyUI datagrid 前端假分页 http://blog.csdn.net/leftfist/article/details/43164977 真分页是easyUI d ...
- Spring中定时器实现
在Spring 中使用Quartz,本文介绍Spring3.0以后自主开发的定时任务工具,spring task,可以将它比作一个轻量级的Quartz,而且使用起来很简单,除spring相关的包外不需 ...
- python 时区
Python中的时区处理 http://tech.glowing.com/cn/dealing-with-timezone-in-python/ Python时区设置方法与pytz查询时区教程_py ...
- YTU 2542: 弟弟的作业
2542: 弟弟的作业 时间限制: 1 Sec 内存限制: 128 MB 提交: 130 解决: 57 题目描述 你的弟弟刚做完了"100以内数的加减法"这部分的作业,请你帮他 ...
- [Codeforces 986E] Prince's Problem
[题目链接] https://codeforces.com/contest/986/problem/E [算法] X到Y的路径积 , 可以转化为X到根的路径积乘Y到根的路径积 , 除以LCA到根的路径 ...
- Face alignment at 3000FPS via Regressing Local Binrary features 理解
这篇是Ren Shaoqing发表在cvpr2014上的paper,论文是在CPR框架下做的,想了解CPR的同学可以参见我之前的博客,网上有同学给出了code,该code部分实现了LBF,链接为htt ...
- ubuntu16.04 查看系统可用内存
free -m 查看内存情况 (单位MB) mem 行显示了从系统角度看来内存使用的情况, total是系统可用的内存大小, 数量上等于系统物理内存减去内核保留的内存. buffers和cach ...