Codeforces CF#628 Education 8 A. Tennis Tournament

A. Tennis Tournament
time limit per test
1 second
memory limit per test
256 megabytes
standard input
standard output

A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.

The tournament takes place in the following way (below, m is the number of the participants of the current round):

  • let k be the maximal power of the number 2 such that k ≤ m,
  • k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
  • when only one participant remains, the tournament finishes.

Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.

Find the number of bottles and towels needed for the tournament.

Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).


The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.


Print two integers x and y — the number of bottles and towels need for the tournament.

5 2 3
20 15
8 2 4
35 32

In the first example will be three rounds:

  1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
  2. in the second round will be only one match, so we need another 5 bottles of water,
  3. in the third round will also be only one match, so we need another 5 bottles of water.

So in total we need 20 bottles of water.

In the second example no participant will move on to some round directly.






 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 using namespace std;
 6 int n, b, p;
 8 int main() {
 9     scanf("%d%d%d", &n, &b, &p);
10     int bottles = 0, towels = n * p;
11     while(n > 1) {
12         int k = 2;
13         while(k * 2 <= n) k <<= 1;
14         int m = n - k + k / 2;
15         int matches = k / 2;
16         bottles += matches * (2 * b + 1);
17         n = m;
18     }
19     printf("%d %d\n", bottles, towels);
20     return 0;
21 }
View Code


posted @ 2016-12-02 11:56  yanzx6  阅读(220)  评论(0编辑  收藏  举报