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