题目连接:http://codeforces.com/problemset/problem/628/A
题目描述
Description
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).
Input
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.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
Sample Input
5 2 3
Sample Output
20 15
Sample Input
8 2 4
Sample Output
35 32
解题思路
毛巾数 = 人数 * p;
计算出一共需要比多少场;
2 * b * 场数 = 运动员需要的;
场数 = 裁判需要的;
相加即可;
AC代码
#include<iostream>
using namespace std;
int main () {
int n, b, p;
int sumb = 0;
int sump = 0;
cin >> n >> b >> p;
sump = n * p;
while(n != 1) {
sumb += n/2;
n = n/2 + n%2;
}
sumb = 2 * b * sumb + sumb;
printf("%d %d", sumb, sump);
return 0;
}