CSU 1727: The Fake Coin

来源:互联网 发布:js与java aes 编辑:程序博客网 时间:2024/05/16 04:44

题目:

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
这个题目,为了加快速度,直接硬编码了。

原理就不说了。。。小学生都会。

代码:

#include<iostream>;using namespace std; int main(){    int t;    cin >> t;    int n;    while (t--)    {        cin >> n;        if (n > 6561)cout << 9;        else if (n > 2187)cout << 8;        else if (n > 729)cout << 7;        else if (n > 243)cout << 6;        else if (n > 81)cout << 5;        else if (n > 27)cout << 4;        else if (n > 9)cout << 3;        else if (n > 3)cout << 2;        else if (n > 1)cout << 1;        else cout << 0;        cout << endl;    }    return 0;}


1 0
原创粉丝点击