Des丨tiny丶柠凉

蓦然回首,前尘不堪流连,自卿离去,暗淡了这俗世繁华,只余孤影几度徘徊,独酌月下,对影成殇;

时间留不住记忆的海,不过是黯然神伤,默默着无奈。


[CF-371C]Hamburgers

题目链接

题目描述

Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite “Le Hamburger de Polycarpus” as a string of letters ‘B’ (bread), ‘S’ (sausage) и ‘C’ (cheese). The ingredients in the recipe go from bottom to top, for example, recipe “ВSCBS” represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.
Polycarpus has nb pieces of bread, ns pieces of sausage and nc pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are pb rubles for a piece of bread, ps for a piece of sausage and pc for a piece of cheese.
Polycarpus has r rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient.

题目大意:

给你一个汉堡的配料,and现有的每种原料的个数,and每种原料的价格,and你有的money;问最多能做几个汉堡。


obviously 这道题具有 二分性质 Thus 直接二分答案 判断买x个汉堡时原料以及钱是否is enough;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<queue>
#include<deque>
#include<stack>
#define LL long long
using namespace std;
char pl[105];
int nb,ns,nc,pb,ps,pc,b,s,c;
LL r;
bool check(LL x){
LL cb = max(((LL)b*x-nb)*pb,(LL)0);
LL cs = max(((LL)s*x-ns)*ps,(LL)0);
LL cc = max(((LL)c*x-nc)*pc,(LL)0);
if(cb+cs+cc <= r) return true;
else return false;
}
int main(){
scanf("%s",pl);
for(int i = 0;i < strlen(pl);i++){
if(pl[i] == 'B') b++;
else if(pl[i] == 'S') s++;
else if(pl[i] == 'C') c++;
}
scanf("%d%d%d",&nb,&ns,&nc);
scanf("%d%d%d",&pb,&ps,&pc);
scanf("%lld",&r);
LL l = 0,r = pow(10,12)*2,mid;
while(l < r){
mid = (l + r)>>1;
if(check(mid))
l = mid+1;
else r = mid;
}
printf("%lld\n",l-1);
return 0;
}

赤果果的大水题!

orz

最近的文章

[CF-676B]Pyramid of Glasses

题目链接 题目描述 Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, s …

于  DP 继续阅读
更早的文章

洛谷[P1044]--栈

题目链接 题目描述 宁宁考虑的是这样一个问题:一个操作数序列,从1,2,一直到n(图示为1到3的情况),栈A的深度大于n。 现在可以进行两种操作, 将一个数,从操作数序列的头端移到栈的头端(对应数据结构栈的push操作) 将一个数,从栈的头端移到输出序列的尾端(对应数据结构栈的pop操作) …

于  卡特兰数, 数学 继续阅读