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?
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?
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.
For each test case, output the least times you need.
3
2
3
4
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; }