您的位置:首页 > 其它

csuoj-1727-The Fake Coin

2016-04-24 18:31 429 查看

Description

There are n coins,one of them is fake.The fake coin is heavier than a genuine one.If you have a balance,how many times at least you need to use it to find the fake coin?

Input

The first line contains an integer T (T<=100), means there are T test cases.

For each test case, there is only one line with an integer n (1 <= n <= 10000). The num of coins.

Output

For each test case, output the least times you need.

Sample Input

3
2
3
4

Sample Output

1
1
2


n个硬币,一个硬币假的比较重,问你最少称几次能把他称出来。

然后分三堆啊

好像初中奥数吧

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define MAXN 10010
using namespace std;

int main()
{
int a[MAXN];
int tot = 1;
a[0] = 1;
for (int i = 1; a[i-1] < MAXN; i++)
{
a[i] = a[i-1] * 3;
tot++;
}
int t;
scanf("%d", &t);
while (t-- )
{
int n;
scanf("%d", &n);
for (int i = 0; i <= tot; i++)
{
if (n <= a[i])
{
printf("%d\n", i);
break;
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: