csuoj-1727-The Fake Coin

来源:互联网 发布:逆波兰式算法 编辑:程序博客网 时间:2024/06/05 04:09

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

3234

Sample Output

112

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

然后分三堆啊

好像初中奥数吧


#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#define MAXN 10010using 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;}


0 0