2386: Find the Coin
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
![]() | 3s | 8192K | 213 | 104 | Standard |
One day, Φ has 8 golden coins. He knew one of them is heavier than others. He wants to find out it. Then he wants to borrow X’s scale. But X is so mean. He said Φ must pay $10 for every use. So Φ ask Keenas for help. After a while , Keenas work out that it just need two times to weight it.
After that, Φ and Keenas want to knew if they have N golden coins, how many times they should use the scale at least? Please help them.
Input
There are many cases.In every case,there is a integer N (0<=N<20000)
Output
Output the minmum number to use scale to find the coin.One case in a line.
Sample Input
0 1 2 8 9
Sample Output
0 0 1 2 2
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int f[21000];
int main()
{
f[2]=f[3]=1;
for(int i=4;i<=20000;i++)
{
if(i%3==0) f[i]=f[i/3]+1;
else if(i%3==1) f[i]=max(f[i/3]+1,f[i/3+1]+1);
else f[i]=max(f[i/3+1]+1,f[i/3]+1);
}
int n;
while(scanf("%d",&n)==1)
{
printf("%d/n",f[n]);
}
return 0;
}