One day frog Frank fall into a deep well, the well is very deep. Everyday Frank try to climb up, at day time, he can get himself feet up, but when he fall sleep at night , he slipped feet down. The well is L feet deep.
Now, it is your turn. Frank is asking you to find out, how many days needed for him to get out from the well. A day has two part, day time and night time. Frank must get higher than the well, or it is not count as get out.
The first line of input contains , the number of test cases. There is one line for each test case, contains three integer numbers as describe above.
For each test case, print a line contains the solution, how many days need for Frank to get out from the well.If there is no way out, please output −1.
2
2 1 2
1 1 2
2
-1
被误解的思路:
本以为 A 2 B 1 L 2 一天就可以爬过去,原来 刚好 A = L 是过不去井口的。所以要 > 井口才可以出的去。
代码:
1 #include<stdio.h> 2 3 int main() 4 { 5 int A,B,L; 6 int t; 7 scanf("%d",&t); 8 while(t>0) 9 { 10 scanf("%d%d%d",&A,&B,&L); 11 if(A<=B) 12 { 13 if(A<=L) 14 printf("-1\n"); 15 else 16 printf("1\n"); 17 } 18 else 19 { 20 if(A>L) 21 printf("1\n"); 22 else 23 printf("%d\n",(int)((L-A)/(A-B))+2); 24 } 25 t--; 26 } 27 28 29 return 0; 30 }