P1423 小玉在游泳

题目描述

小玉开心的在游泳,可是她很快难过的发现,自己的力气不够,游泳好累哦。已知小玉第一步能游2米,可是随着越来越累,力气越来越小,她接下来的每一步都只能游出上一步距离的98%。现在小玉想知道,如果要游到距离x米的地方,她需要游多少步呢。请你编程解决这个问题。

输入格式

输入一个数字(不一定是整数,小于100m),表示要游的目标距离。

输出格式

输出一个整数,表示小玉一共需要游多少步。

输入输出样例

输入 #1
4.3
输出 #1
3
 1 #include<iostream>
 2 
 3 using namespace std;
 4 
 5 int main(){
 6     double a;
 7     scanf("%lf",&a);
 8         //double加0.0000就完事了
 9     double dis = 2.0000;
10     double last = 2.0000;
11     int times = 1;
12     while(a > dis){
13         last = last * 0.98;  
14         dis += last;
15         times++;
16     }    
17     printf("%d",times);
18     return 0;
19     
20 }
原文地址:https://www.cnblogs.com/luyuan-chen/p/11607778.html