二分搜索 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个数 ...
随机推荐
- struct init
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h& ...
- Nginx配置文件nginx.conf 详解
#定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; #全局错误日志定义类型,[ debu ...
- Codeforces Round #457 (Div. 2) B
B. Jamie and Binary Sequence (changed after round) time limit per test 2 seconds memory limit per te ...
- SecurityContextHolder.getContext().getAuthentication()为null的情况
原理: UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication() . ...
- 消息队列RabbitMQ使用教程收集
学习应该要系统,最好的方式是看书. RabbitMQ最权威的教程应该参考官方文档. 下面是收集的一些教程: 官方: https://www.rabbitmq.com/getstarted.html h ...
- springboot整体介绍
1.springboot:快速开发,强大的运维能力.(监控,服务发现,并打) 2.微服务,将一个大系统分解成很多独立的小服务,这些服务能随时发布. 3.2004年第一版spring 1.0,rod j ...
- Linux命令输出头(标题)、输出结果排序技巧
原文:http://blog.csdn.net/hongweigg/article/details/65446007 ----------------------------------------- ...
- Android Studio签名打包应用
转载请注明来源: http://blog.csdn.net/kjunchen/article/details/50812391 可直接看看以下的Android Studio中签名应用 Android要 ...
- 图像处理之基础---彩色转灰度算法优化rgb to yuv
File: StudyRGB2Gray.txtName: 彩色转灰度算法彻底学习Author: zyl910Version: V1.0Updata: 2006-5- ...
- java json字符串转成 Map或List
import java.util.List; import java.util.Map; import java.util.Map.Entry; import net.sf.json.JSONArra ...