因为痛,所以叫青春

我有一个梦想:穷屌丝变身富屌丝
uva573 - The Snail

注意一点,蜗牛不能向下爬,所以蜗牛爬行的距离不能是负数

View Code
 1 #include<stdio.h>
 2 int main()
 3 {
 4     double h, u, d, f, p, q;
 5     int k;
 6     while(scanf("%lf%lf%lf%lf",&h,&u,&d,&f))
 7     {
 8         if(int(h) == 0)
 9             break;
10         q = h;
11         k = 1;
12         p = u/100*f;
13         while(1)
14         {
15             h -= u;
16             u -= p;
17             if(u < 0)
18                 u = 0;
19             if(h < 0)
20             {
21                 printf("success on day %d\n",k);
22                 break;
23             }
24             h += d;
25             if(h > q)
26             {
27                 printf("failure on day %d\n",k);
28                 break;
29             }
30             k++;
31         }
32     }
33     return 0;
34 }

posted on 2012-07-21 15:49  Nice!  阅读(184)  评论(0编辑  收藏  举报