CF 628A---Tennis tournament---water problem

Source: Internet
Author: User

CF 628A

Title: Given N,b,p, where n is the number of people who are going to play, B is the amount of water that each athlete needs for each game,

P The number of towels provided to each athlete for the entire schedule,

Each time in the remaining n number of people, the selection of 2^k=m (M <=n) individuals to compete, the remaining n-m individual direct promotion,

Until one person is left, ask for the total quantity of water and the number of towels required

Problem-Solving ideas: The number of towels is simple: n*p can

Quantity of water: 1,2,4,8,16,32,64,128,256,512, in advance into a table,

According to the number of people currently remaining n in the table to find the largest number of less than equals N, the result is the number of participants in the tournament, recorded as A[pos]

Calculate the corresponding amount of water according to A[pos] and use the N-A[POS]/2 (elimination number) for the next round of calculations until N is 1

/*CF 628A---tennis tournament---water problem*/#include<cstdio>#include<algorithm>using namespacestd;intA[] = {1,2,4,8, -, +, -, -, the, + };//find first position less than or equal to key in {x, y) of aintBinarySearch (intXintYintkey) {     while(X <y) {        intMID = x + (y-x)/2; if(A[mid] <= key && A[mid +1] >key) {            returnmid; }        Else if(A[mid] >key) {y=mid; }        Else{x= mid+1; }    }    return-1;}intMain () {#ifdef _local freopen ("D:input.txt","R", stdin);#endif    intN, b, p;  while(SCANF ("%d%d%d", &n, &b, &p) = =3){        intsum =0; intt =N;  while(t! =1){            //find out how many people the current T person needs to play            intpos = BinarySearch (0,9, t);//A[pos] That is, the number of A[POS]/2 in the contest is the number of judgesSum + = (A[pos] * b + a[pos]/2); T-= (A[pos]/2);//minus the eliminated A[POS]/2 is the remaining number.} printf ("%d%d\n", SUM, np); }    return 0;}
View Code

       

CF 628A---Tennis tournament---water problem

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.