P1423 Xiaoyu swimming, P1423 Xiaoyu swimming
Description
XiaoYu was happy to swim, but she quickly found out that she was not strong enough to swim very tired. It is known that XiaoYu can swim 2 meters in the first step, but as she gets tired and has little strength, she can only swim 98% away from the previous step in every step. Now, XiaoYu wants to know how many steps she needs to travel to a place x meters away. Please program to solve this problem.
Input/Output Format
Input Format:
Enter a number (not necessarily an integer, less than 100 m) to indicate the target distance of the game.
Output Format:
The output is an integer indicating the total number of steps that XiaoYu needs to swim.
Input and Output sample input sample #1:
4.3
Output sample #1:
3
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#define lli long long int using namespace std;void read(int &n){char c='+';int x=0;bool flag=0;while(c<'0'||c>'9'){c=getchar();if(c=='-')flag=1;}while(c>='0'&&c<='9')x=x*10+(c-48),c=getchar();flag==1?n=-x:n=x;}int a[10];double will;double now=0;double base=2;int step;int main(){cin>>will;while(now<will){step++;now+=base;base*=0.98;}printf("%d",step);return 0;}