Topic Portal
1 /*2 Test instructions: A hamburger made from a string, has some raw materials, and money can go to the store to buy raw materials, ask to make a few hamburgers3 two points: the number of hamburgers, judging whether the money spent at this time is within the stipulated4 */5#include <cstdio>6#include <algorithm>7#include <cmath>8 using namespacestd;9 TentypedefLong Longll; One Const intMAXN = 1e2 +Ten; A Const intINF =0x3f3f3f3f; - CharHAM[MAXN]; - LL NB, NS, NC; the ll PB, PS, PC; - ll B, S, C; - ll M; - + BOOLCheck (ll x) { -ll cost =0; + if(b * x > NB) Cost + = (b * x-nb) *PB; A if(S * x > NS) Cost + = (S * x-ns) *PS; at if(c * x > NC) Cost + = (c * X-NC) *pc; - returnCost <=m; - } - - intMainvoid) {//codeforces Round #218 (Div. 2) C. Hamburgers -scanf ("%s", &ham); inscanf ("%i64d%i64d%i64d", &NB, &ns, &NC); -scanf ("%i64d%i64d%i64d", &PB, &ps, &pc); toscanf ("%i64d", &m); +b = s = c =0; - for(intI=0; Ham[i]; ++i) { the if(Ham[i] = ='B') b++; * Else if(Ham[i] = ='S') s++; $ ElseC++;Panax Notoginseng } -ll L =0, r =1e13; the while(L +1<r) { +ll mid = (L + r) >>1; A if(Check (mid)) L =mid; the ElseR =mid; + } -printf ("%i64d\n", L); $ $ return 0; -}
Binary search Codeforces Round #218 (Div. 2) C. Hamburgers