一口井N米深,井底有一只蜗牛,蜗牛第一天白天能爬X米,每天晚上掉下2米(最多掉到井底),第一天之后每天白天能向上爬的距离只有前一天的95%。请你计算蜗牛能否爬到井口,如果能,输出蜗牛在第几天爬到井口。
Input
输入数据包含两个实数N和X,N( 0 < N <= 10000)代表井深,X( 0 < X <= 10000)代表第一天白天蜗牛能爬多高。
Output
如果蜗牛能爬出井口输出爬出的天数,如果不能爬出井口输出-1.
Sample Input
10 3
Sample Output
-1
只要判断条件是否符合就行了。
int Out(){
float N,X,dep = 0;
int count = 0;
printf("Depth: ");
scanf("%d",&N);
printf("Speed: ");
scanf("%d",&X);
while( dep >= 0 ){
count++;
dep += X;
if( dep >= N ){
return count;
}
dep = dep - 2;
X = X*0.95;
}
return -1;
}