hdu1302 The Snail

0人阅读 评论(0) 收藏 举报

题目

题目大意:

一只蜗牛在H英尺高的底部,想爬到顶端。蜗牛可以在太阳升起的时候爬上U英尺,但是在晚上睡觉的时候会滑下D英尺。蜗牛的疲劳系数为F(百分比),                                                                                                                                                 这意味着蜗牛在每一天都比前一天少爬(F/100*U)英尺                                                                                               【这个地方一直理解错了*(理解成了每天都比前一天少爬[F/100*(前一天爬的高度)])】。                                            问:蜗牛第几天离开井?

还有注意细节,定义数据类型是double,理解题意的顺序执行过程,不要把顺序搞错了。

#include<stdio.h>
int main()
{
    int day;
    double H,U,D,F;
    double s,sum;
    while(scanf("%lf%lf%lf%lf",&H,&U,&D,&F),H)
    {
        s=U;
        sum=0;
        day=0;
        while(1)
        {
            day++;

            if(s>0)
                sum+=s;
            if(sum>H) break;
            sum = sum-D;
            if(sum<0)
                break;
            s=s-F*U/100.0;
        }
         if(sum>H)  printf("success on day %d\n",day);
        else printf("failure on day %d\n",day);
    }
    return 0;
}


查看评论

HDU1302:The Snail

Problem Description A snail is at the bottom of a 6-foot well and wants to climb to the top. The sn...
  • libin56842
  • libin56842
  • 2013-04-27 19:43:22
  • 1625

HDU1302 The Snail

1302The SnailTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To...
  • lx0208
  • lx0208
  • 2017-07-30 13:56:43
  • 87

Snail的编程感悟

一个又一个版本的更新,CSDN和我一起见证着Snail Language的长大。从2013年到2014年,从未停止过编写代码的步伐,从未停止过为它添加新功能的想法。写Snail的目的何其简单,只是为了...
  • u012813593
  • u012813593
  • 2014-01-17 19:34:29
  • 1276

hdu 1302(The Snail)

The Snail Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...
  • Ice_Alone
  • Ice_Alone
  • 2014-10-19 14:10:37
  • 933

hdu 1302 The Snail

The Snail Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota...
  • ling_du
  • ling_du
  • 2014-11-01 19:18:58
  • 546

uva 573 - The Snail

The Snail  A snail is at the bottom of a 6-foot well and wants to climb to the top. The sna...
  • Frankiller
  • Frankiller
  • 2012-06-15 21:05:32
  • 747

hdu1302

The Snail Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...
  • u013447865
  • u013447865
  • 2014-08-21 14:25:46
  • 422

hdu1302The Snail

The Snail Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota...
  • sungaochao
  • sungaochao
  • 2014-11-08 20:01:30
  • 417

杭电ACM-The Snail

Problem Description A snail is at the bottom of a 6-foot well and wants to climb to the top. The ...
  • mayuko2012
  • mayuko2012
  • 2015-01-28 11:39:25
  • 710

HDU1302_Snail【模拟题】【水题】

题目大意:蜗牛从井底向上爬高,井深H米,早上爬U米,晚上下滑D米,且它 从第二天开始每天疲劳,每天比第一天少F%,问最后第几天能爬出井或者不能爬 出井而失败。 思路:简单模拟,按照题目要求做就可以。...
  • u011676797
  • u011676797
  • 2014-11-20 07:29:33
  • 1196
    个人资料
    持之以恒
    等级:
    访问量: 8956
    积分: 1055
    排名: 4万+
    博客专栏
    最新评论
  • 错误提示

    qie_wei: 有时候报编译错误(Compilation Error),可能是使用到了关键字,把关键字,用其他字符...