题目大意:
一项比赛,给定competitors数量,如果是even,那么两两PK,胜者进入下一轮,如果非even,那么随机选一个进入下一轮,剩下的人两两PK。问需要多少轮可以选出champion。
解题思路:
看这个数是2的几次方向上取整就可以了
代码如下:
#include <iostream>
#include <math.h>
using namespace std;
int main ()
{
long n;
while(cin>>n&&n)
{
int round;
round = ceil(log10((double)n)/log10(2.0));
cout<<round<<endl;
}
return 0;
}
497

被折叠的 条评论
为什么被折叠?



