https://leetcode.com/problems/poor-pigs/
Package Com.company;classSolution {//The second approach seems to OJ the original approach, but it is wrong//read the answer.https://discuss.leetcode.com/topic/66856/major-flaw-in-current-algorithm-fixed Public intPoorpigs (intBucketsintMinutestodie,intminutestotest) { //There are 5 different states intCircle = Minutestotest/minutestodie +1; intRET =0; Longnum =1; while(Num <buckets) {num*=Circle; RET++; } returnret; }
The following answer is not quite right . Public intPOORPIGS2 (intBucketsintMinutestodie,intminutestotest) { if(Minutestodie = =0) { return 0; } intCircle = minutestotest/Minutestodie; if(Circle = =0) { return 0; } intBatch = (buckets + (Circle-1)) /Circle; intRET =0; Longnum =1; while(Num <Batch) {num*=2; RET++; } if(num = = Batch && Circle! =1) { returnRET +1; } Else { returnret; } }} Public classMain { Public Static voidMain (string[] args) throws Interruptedexception {System. out. println ("hello!"); Solution Solution=Newsolution (); //Your Codec object would be instantiated and called as such: intret = Solution.poorpigs ( +, the, -); System. out. printf ("ret:%d\n", ret); System. out. println (); }}
Poor-pigs (very good idea)