<题目链接>

题目大意:

给以一段字符串,其中只包含"BSC"这三个字符,现在有一定量免费的'B','S','C‘,然后如果想再买这三个字符,就要付出相应的价格。现在总共有tot元,问你最多能够组成几个这样的字符串。

解题分析:

开始还以为是模拟,但是看到总价的范围,达到了1e12,并且模拟的情况非常复杂。最后用二分答案求解。

#include <cstdio>
#include <cstring>
using namespace std; typedef long long ll;
const ll maxn = 1e12+100; //本题二分答案的上界
char str[110];
int base[4],price[4],ned[4];
ll tot; bool juge(ll x) { //判断是否能够买这么多汉堡,即验证二分答案的正确性
ll sum = 0;
for (int i = 1; i <=3; i++) {
if (base[i] < x*ned[i]) {
sum += (price[i] * (x*ned[i] - base[i]));
if(sum>tot)return false;
}
}
return true;
}
ll binary_ans(){
ll l=0,r=maxn,ans=0;
while(l<=r){
ll mid=(l+r)>>1;
if(juge(mid))ans=mid,l=mid+1;
else r=mid-1;
}return ans;
}
int main() {
scanf("%s",str);
memset(ned, 0, sizeof(ned));
for (int i = 0; i < strlen(str); i++) {
if (str[i] == 'B')ned[1]++;
if (str[i] == 'S')ned[2]++;
if (str[i] == 'C')ned[3]++;
}
for (int i = 1; i <= 3; i++)
scanf("%d", &base[i]);
for (int i = 1; i <= 3; i++)
scanf("%d", &price[i]);
scanf("%lld", &tot);
printf("%lld\n", binary_ans());
return 0;
}

  

CodeForces 371C Hamburgers(经典)【二分答案】的更多相关文章

  1. [Codeforces 1199C]MP3(离散化+二分答案)

    [Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...

  2. Codeforces 371C Hamburgers (二分答案)

    题目链接 Hamburgers 二分答案,贪心判断即可. #include <bits/stdc++.h> using namespace std; #define REP(i,n) fo ...

  3. Codeforces 772A Voltage Keepsake - 二分答案

    You have n devices that you want to use simultaneously. The i-th device uses ai units of power per s ...

  4. 2018.12.08 codeforces 939E. Maximize!(二分答案)

    传送门 二分答案好题. 题意简述:要求支持动态在一个数列队尾加入一个新的数(保证数列单增),查询所有子数列的 最大值减平均值 的最大值. 然而网上一堆高人是用三分做的. 我们先考虑当前的答案有可能由什 ...

  5. Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案

    Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...

  6. 洛谷 P2678 跳石头【经典二分答案/贪心】

    题目描述 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起点和终点.在起点和终点之间,有 NN 块岩石(不含起点和终点的岩石).在比赛过程中,选手们将从 ...

  7. CodeForces 371C Hamburgers

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

  8. Codeforces 700A As Fast As Possible(二分答案)

    [题目链接] http://codeforces.com/problemset/problem/700/A [题目大意] 有一辆限载k人速度为v2的车,n个步行速度均为v1的人要通过一段长度为l的距离 ...

  9. Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)

    链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...

随机推荐

  1. windows Sever 2012下Oracle 12c安装配置方法图文教程

    windows Sever 2012下Oracle 12c安装配置方法图文教程 Oracle 12c安装配置方法图文教程,具体内容如下 1.我们开启虚拟机 2.Windows Sever 2012启动 ...

  2. python之通过thread来实现多进程

    代码如下: import threading, time class Test1(threading.Thread): def __init__(self, name): super().__init ...

  3. 浅谈js的join()方法

    简单描述:今天看同事的代码,看js的时候,看到了一个join()方法,我从来都没有用过,就查了查,第一次用就记录一下 正经的: 定义和用法 join() 方法用于把数组中的所有元素放入一个字符串. 元 ...

  4. django----Form实时更新两种方式

    在ModelForm需要知道: from app03 import models from django.forms import ModelForm class UserForm(ModelForm ...

  5. python调用PHP方法

    PHP代码如下:<?php $method = $argv[1]; $param1 = $argv[2]; $param2 = $argv[3]; if(isset($method) & ...

  6. AI-视图组件-五个接口的最终简化版

    五个接口最终版 #url.py # 序列化最贱版本 url(r'^customer/$', views.CustomerView.as_view({"get":"list ...

  7. Selenium+PhantomJS使用时报错原因及解决方案

    问题 今天在使用selenium+PhantomJS动态抓取网页时,出现如下报错信息: UserWarning: Selenium support for PhantomJS has been dep ...

  8. Python模块的导入以及软件开发规范

    Python文件的两种用途 1 . 当脚本直接使用,直接当脚本运行调用即可 def func(): print("from func1") func() 2 . 当做模块被导入使用 ...

  9. Tomcat8 启动慢 Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [53,161] milliseconds

    修改$JAVA_PATH/jre/lib/security/java.security文件 将 securerandom.source=file:/dev/random 修改为 securerando ...

  10. Node 杂技

    1.关于require 当文件夹a中含有index.js时,在b.js中如果有require("文件夹a的路径"),则将会自动执行index.js的语句