table tennis ╮(╯▽╰)╭
阿新 • • 發佈:2019-02-13
Problem Description
There are N table tennis, and only one of them has quality problem which is lighter than a normal ball. Give you a balance without any weights, calculate the minimum number of times that you can guarantee to find the bad one.Input
Multiple cases. Each case is a single integer n (1<=n<=1000).Output
Sample Input
2 6
Sample Output
1 2
#include <iostream> using namespace std; int f[1002]; int main() { f[0]=0; f[1]=0; f[2]=1; f[3]=1; for(int i=4;i<=1000;i++) { if((i/3)*3<i) { f[i]=f[i/3+1]+1; } else f[i]=f[i/3]+1; } int a; while(scanf("%d",&a)!=EOF) { cout<<f[a]<<endl; } return 0; }