二分搜索 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个数 ...
随机推荐
- 详解SpringBoot集成jsp(附源码)+遇到的坑
本文介绍了SpringBoot集成jsp(附源码)+遇到的坑 ,分享给大家 1.大体步骤 (1)创建Maven web project: (2)在pom.xml文件添加依赖: (3)配置applica ...
- Java:PPT(X)转图片、PDF和SVG
(一) 简介: 工作中,PowerPoint文档有时需要被转换为PDF/图像文件来存档.因为PDF或图片的页面布局是固定的,很难被修改且能被大多数设备打开,所以PDF或者图片比起PowerPoint格 ...
- 用JQ实现基础的添加,插入,删除功能。
在eclipse里面运行代码即可,如果您是其他应用,请选择对您有帮助的代码即可,如果有写错或不懂的地方请联系QQ:1633420056,谢谢,祝学习进步 <!DOCTYPE html>&l ...
- spring boot项目自定义数据源,mybatisplus分页、逻辑删除无效解决方法
Spring Boot项目中数据源的配置可以通过两种方式实现: 1.application.yml或者application.properties配置 2.注入DataSource及SqlSessio ...
- 详解MySQL分区表
当数据库数据量涨到一定数量时,性能就成为我们不能不关注的问题,如何优化呢? 常用的方式不外乎那么几种: 1.分表,即把一个很大的表达数据分到几个表中,这样每个表数据都不多. 优点:提高并发量,减小锁的 ...
- jqury-validate表单验证
首先需要引入插件:jquery.validate.js这个插件. 然后对需要验证的表单实现js: $("#add-firewalls-form").validate({ submi ...
- Eclipse插件开发中的选择监听机制(Selection Provider-Listener)
Eclipse插件开发中的选择监听机制(Selection Provider-Listener) 监听机制是eclipse插件开发或rcp应用开发中经常使用的技术,比方点击TableViewer或Tr ...
- MySQL-删除数据(DELECT)
数据库备份介绍: 数据库一旦删除数据,它就会永远消失. 因此,在执行DELETE语句之前,应该先备份数据库,以防万一要找回删除过的数据. MySQL提供了非常有用的工具,用于在服务器上本地备份或转储M ...
- Python extensions for Windows
Python extensions for Windows pywin32 214 Python extensions for Windows Maintainer: Mark Hammond Hom ...
- mysql_connect 等待时间长,修改连接地址为127.0.0.1即可
程序搬家后,运行非常慢分析流程: 1.外网的等待时间太长 2.内容等待时间也很长 3.断点查到仅仅一句 mysql_connect ("localhost",***,***)就要1 ...