A-HamburgersTime Limit: +MsMemory Limit:262144Kb64bit IO Format:%i64d &%i64u
Description
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there is 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 " re Presents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again.
Polycarpus has n b pieces of bread , n s pieces of sausage And n c pieces of cheese in the kitchen. Besides, the shop nearby have all three ingredients, the prices Are p b rubles for a piece of Bread, p s for a piece of sausage and p C for a piece of cheese.
Polycarpus has R rubles and he are ready-to-shop on them. What maximum number of hamburgers can he cook? You can assume this polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has a unlimited number of pieces of each ingredient.
Input
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn ' t exceed, the string contains only letters 'B' (Uppercase 中文版b), 's' (uppercase 中文版s) and 'C' (uppercase EnglishC).
The second line contains three integers nb , ns , nc (1?≤? N b,? N s,? N C. ≤?100 )-the number of the pieces of bread, sausage and cheese on polycarpus ' kitchen. The third line contains three integers Pb , Ps , Pc (1?≤? P b,? P s,? P C. ≤?100 )-the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integerR(1?≤? r. ≤?10 )-the number of rubles Polycarpus has.
Please, don't write the %lld specifier to read or write 64-bit integers inс++. It is preferred to use thecin, cout streams or the%i64d specifier.
Output
Print the maximum number of hamburgers Polycarpus can make. If He can ' t make any hamburger, print0.
Sample Input
Input
BBBSSC6 4 11 2 34
Output
2
Input
BBC1 10 11 10 121
Output
7
Input
BSC1 1 11 1 31000000000000
Output
200000000001
simple two points. This is our weekly race with VJ grilled problem, at that time the game is a variety of points of the situation, think a little dizzy did not do, and later reminded that it is two points, just want to understand, quite simple. The upper bound is obtained by two points.
#include <stdio.h> #include <string.h> #include <map> #include <queue> #include <algorithm >using namespace Std;typedef __int64 ll;const ll max=1000000000000+100;ll Need[4],pos[4],pri[4],money; Need make a hamburger need the amount of material, POS owned, PRI Price, money owned by Char s[105];//determine whether it is able to make X burger bool C (ll x) {ll i,sum=0;for (i=1;i<=3;i++) if ( Pos[i]<x*need[i]//If you have enough material to do X, calculate how much money you need to buy the material sum+=pri[i]* (x*need[i]-pos[i]); return money>=sum;//money is enough for true }ll Upper_bound () {ll l,r,mid;l=0;r=max;while (l<r) {mid= (l+r)/2+1;//plus 1 processing can prevent dead loops,--bif (C (mid)) L=mid;else R=mid-1;} return l;} int main () {ll i,j,k;scanf ("%s", s); scanf ("%i64d%i64d%i64d", &pos[1],&pos[2],&pos[3]); scanf ("%i64d%i64d %i64d%i64d ", &pri[1],&pri[2],&pri[3],&money); memset (need,0,sizeof (need)); for (i=0;s[i]!= '); i++ {if (s[i]== ' B ') need[1]++;if (s[i]== ' s ') need[2]++;if (s[i]== ' C ') need[3]++;} printf ("%i64d\n", Upper_bound ()); return 0;}
Codeforces 371C Hamburgers (two minutes)