Binary search Codeforces Round #218 (Div. 2) C. Hamburgers

Source: Internet
Author: User

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", &AMP;NB, &ns, &NC); -scanf ("%i64d%i64d%i64d", &AMP;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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.