洛谷1423 小玉在游泳

洛谷1423 小玉在游泳

本题地址: http://www.luogu.org/problem/show?pid=1423

题目描述

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

输入输出格式

输入格式:

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

输出格式:

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

输入输出样例

输入样例#1:

4.3

输出样例#1:

3
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<stack>
 6 #include<queue>
 7 #include<cstring>
 8 #define PAU putchar(' ')
 9 #define ENT putchar('\n')
10 #define MSE(a,b) memset(a,b,sizeof(a))
11 #define REN(x) for(ted*e=fch[x];e;e=e->nxt)
12 #define TIL(x) for(int i=1;i<=x;i++)
13 #define ALL(x) for(int j=1;j<=x;j++)
14 using namespace std;
15 const double eps=1e-7;
16 inline int read(){
17     int x=0;bool sig=true;char ch=getchar();
18     for(;!isdigit(ch);ch=getchar())if(ch=='-')sig=false;
19     for(;isdigit(ch);ch=getchar())x=10*x+ch-'0';return sig?x:-x;
20 }
21 inline void write(int x){
22     if(x==0){putchar('0');return;}if(x<0)putchar('-'),x=-x;
23     int len=0;static int buf[20];while(x)buf[len++]=x%10,x/=10;
24     for(int i=len-1;i>=0;i--)putchar(buf[i]+'0');return;
25 }
26 int main(){
27     double d;scanf("%lf",&d);double a=2.0,sum=2.0;int tot=1;
28     TIL(1000000){
29         if(sum+eps>d){write(tot);return 0;}
30         tot++;a=a*0.98;sum+=a;
31     }
32     return 0;
33 }

 

posted @ 2015-08-22 13:50  AI_Believer  阅读(461)  评论(0编辑  收藏  举报