一个乱七八糟的故事背景,可以练练英语阅读。

大概的意思是Polycarpus喜欢汉堡,现在他有你ns片香肠片,nb面包,nc块起司,有r卢布,每种东西都有价格,如果不够他可以去商店买(商店里面各种东西都是无限多的),制作汉堡需要多少各种东西都已经用字符串给出了,求他最多可以制作出多少汉堡。

简单二分,主意的是二分的上界,可能会超过10^12,就因为这个WA了两次。

#include <stdio.h>
#include <string.h>
#define maxn 2000000000000
#define ll long long
#include <iostream> using namespace std; int cntb, cnts, cntc;
int nb, ns, nc;
int pb, ps, pc;
ll r;
char str[105]; ll cal(ll x)
{
ll sum = 0;
if (x*cntb - nb > 0)
sum += (x*cntb - nb) * pb;
if (x*cntc - nc > 0)
sum += (x*cntc - nc) * pc;
if (x*cnts - ns > 0)
sum += (x*cnts - ns) * ps;
return sum;
} ll binarysearch(ll l, ll r, ll x)
{
//cout << l << " " << r << " " << x << endl;
if (l == r)
{
while (cal(l) > x)
l--;
return l;
} ll mid = (l+r)>>1;
if (cal(mid) > x)
return binarysearch(l, mid, x);
else
return binarysearch(mid+1, r, x);
} int main()
{
while (scanf("%s", str) != EOF)
{
int len = strlen(str);
cntb = 0, cnts = 0, cntc = 0;
for (int i = 0; i < len; i++)
{
if (str[i] == 'B')
cntb++;
else if (str[i] == 'S')
cnts++;
else if (str[i] == 'C')
cntc++;
}
scanf("%d %d %d", &nb, &ns, &nc);
scanf("%d %d %d", &pb, &ps, &pc);
cin >> r;
cout << binarysearch(0, maxn, (ll)r) << endl;
}
return 0;
}

codeforces 371 C-Hamburgers的更多相关文章

  1. Codeforces#371 Div2

    这是一场非常需要总结的比赛,交了3题,最后终测的时候3题全部没过,一下掉到了绿名,2333 Problem A 题意:给定区间[l1,r1],[l2,r2],然后给定一个整数k,求区间当中相交的元素, ...

  2. C++练习 | 二分练习

    Codeforces 371C : Hamburgers #include<bits/stdc++.h> using namespace std; char B='B',S='S',C=' ...

  3. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  4. 二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers

    题目传送门 /* 题意:一个汉堡制作由字符串得出,自己有一些原材料,还有钱可以去商店购买原材料,问最多能做几个汉堡 二分:二分汉堡个数,判断此时所花费的钱是否在规定以内 */ #include < ...

  5. Codeforces Round #371 (Div. 2)B. Filya and Homework

    题目链接:http://codeforces.com/problemset/problem/714/B 题目大意: 第一行输入一个n,第二行输入n个数,求是否能找出一个数x,使得n个数中的部分数加上x ...

  6. Codeforces Round #371 (Div. 2) - B

    题目链接:http://codeforces.com/contest/714/problem/B 题意:给定一个长度为N的初始序列,然后问是否能找到一个值x,然后使得序列的每个元素+x/-x/不变,最 ...

  7. Codeforces Round #371 (Div. 2) - A

    题目链接:http://codeforces.com/contest/714/problem/A 题意:有两个人A,B 给定A的时间区间[L1,R1], B的时间区间[L2,R2],然后在正好K分钟的 ...

  8. Codeforces Round #218 (Div. 2) C. Hamburgers

    C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. CodeForces 371C Hamburgers

    B题又耽误时间了...人太挫了.... C. Hamburgers time limit per test 1 second memory limit per test 256 megabytes i ...

随机推荐

  1. spring cloud 系列第4篇 —— feign 声明式服务调用 (F版本)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.feign 简介 在上一个用例中,我们使用ribbon+restTem ...

  2. 33 | 无实例无真相:基于LoadRunner实现企业级服务器端性能测试的实践(下)

  3. spring源码深度解析— IOC 之 开启 bean 的加载

    概述 前面我们已经分析了spring对于xml配置文件的解析,将分析的信息组装成 BeanDefinition,并将其保存注册到相应的 BeanDefinitionRegistry 中.至此,Spri ...

  4. putty秘钥转换成xhell支持的格式

    使用XShell导入KEY的时候报“Failed to import the user key!”错误 这个错误表明导入的private key文件不是XShell所支持的,有三种可能: 将Publi ...

  5. 在django中使用vue.js需要注意的地方

    有接口如下: http://127.0.0.1:8000/info/schemes/ 返回json数据: [ { "name": "(山上双人标准间)黄山经典二日游(魅力 ...

  6. POJ 3621:Sightseeing Cows(最优比率环)

    http://poj.org/problem?id=3621 题意:有n个点m条有向边,每个点有一个点权val[i],边有边权w(i, j).找一个环使得Σ(val) / Σ(w)最大,并输出. 思路 ...

  7. 十分钟教你理解TypeScript中的泛型

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者.原文出处:https://blog.bitsrc.io/understanding-generics-in-t ...

  8. 未能加载文件或程序集“Seagull.BarTender.Print, Version=11.0.8.1, Culture=neutral, PublicKeyToken=109ff779a1b4cbc7

    这2天项目上需要使用BarTender打印软件,使用BarTender的库的时候时候发现一个特别的问题: 未能加载文件或程序集“Seagull.BarTender.Print, Version=11. ...

  9. 《Python 3网络爬虫开发实战中文》超清PDF+源代码+书籍软件包

    <Python 3网络爬虫开发实战中文>PDF+源代码+书籍软件包 下载: 链接:https://pan.baidu.com/s/18yqCr7i9x_vTazuMPzL23Q 提取码:i ...

  10. NOSQL—MongoDB之外的新选择

    MongoDB之外的新选择 MongoDB拥有灵活的文档型数据结构和方便的操作语法,在新兴的互联网应用中得到了广泛的部署,但对于其底层的存储引擎一直未对外开放,虽说开源却有失完整.Mongo版本3中开 ...