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

大概的意思是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. 为什么string是引用类型 值还不可以修改

    C#把数据类型分为值类型和引用类型.值类型操作简单,引用类型更省空间. C#一共有15个预定义类型,其中13个值类型(8个整型.2个浮点类型.decimal.bool.char),2个引用类型(str ...

  2. python算法与数据结构-数据结构中常用树的介绍(45)

    一.树的定义 树是一种非线性的数据结构,是由n(n >=0)个结点组成的有限集合.如果n==0,树为空树.如果n>0,树有一个特定的结点,根结点根结点只有直接后继,没有直接前驱.除根结点以 ...

  3. 用户点击获取验证码之后我们会发送一条信息到用户手机,然后就会出现一个倒计时按钮,很像支付宝手机付款效果了,下面我给大家分享两个js效果

    js代码  代码如下 复制代码 <div class="input">    <input type="button" id="bt ...

  4. 关于elasticsearch安装及搭建集群时候的错误

    1,在Windows上解压后启动elasticsearch后可能cmd中会抛出java 无法初始话异常,网上查询必须用的是jdk1.8以上,可是本人用的 就是jdk1.8啊,半天解决无果,最后重新安装 ...

  5. 并发编程-concurrent指南-原子操作类-AtomicReference

    1.类 AtomicReference<V> public class AtomicReference<V>extends Objectimplements Serializa ...

  6. 安装Eclipse for MAC 苹果版

    1. 安装Eclipse for MAC 苹果版 2. Thank you for downloading Eclipse If the download doesn't start in a few ...

  7. 使用react+redux+react-redux+react-router+axios+scss技术栈从0到1开发一个applist应用

    先看效果图 github地址 github仓库 在线访问 初始化项目 #创建项目 create-react-app applist #如果没有安装create-react-app的话,先安装 npm ...

  8. 数据结构-循环队列(Python实现)

    今天我们来到了循环队列这一节,之前的文章中,我介绍过了用python自带的列表来实现队列,这是最简单的实现方法. 但是,我们都知道,在列表中删除第一个元素和删除最后一个元素花费的时间代价是不一样的,删 ...

  9. Bzoj 3126[Usaco2013 Open]Photo 题解

    3126: [Usaco2013 Open]Photo Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 335  Solved: 169[Submit] ...

  10. Leetcode solution 291: Word Pattern II

    Problem Statement Given a pattern and a string str, find if str follows the same pattern. Here follo ...