题干:

A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail has a fatigue factor of 10%, which means that on each successive day the snail climbs 10% * 3 = 0.3 feet less than it did the previous day. (The distance lost to fatigue is always 10% of the first day's climbing distance.) On what day does the snail leave the well, i.e., what is the first day during which the snail's height exceeds 6 feet? (A day consists of a period of sunlight followed by a period of darkness.) As you can see from the following table, the snail leaves the well during the third day.

Day Initial Height Distance Climbed Height After Climbing Height After Sliding 
1 0 3 3 2 
2 2 2.7 4.7 3.7 
3 3.7 2.4 6.1 -

Your job is to solve this problem in general. Depending on the parameters of the problem, the snail will eventually either leave the well or slide back to the bottom of the well. (In other words, the snail's height will exceed the height of the well or become negative.) You must find out which happens first and on what day.

Input

The input file contains one or more test cases, each on a line by itself. Each line contains four integers H, U, D, and F, separated by a single space. If H = 0 it signals the end of the input; otherwise, all four numbers will be between 1 and 100, inclusive. H is the height of the well in feet, U is the distance in feet that the snail can climb during the day, D is the distance in feet that the snail slides down during the night, and F is the fatigue factor expressed as a percentage. The snail never climbs a negative distance. If the fatigue factor drops the snail's climbing distance below zero, the snail does not climb at all that day. Regardless of how far the snail climbed, it always slides D feet at night.

Output

For each test case, output a line indicating whether the snail succeeded (left the well) or failed (slid back to the bottom) and on what day. Format the output exactly as shown in the example.

Sample Input

6 3 1 10
10 2 1 50
50 5 3 14
50 6 4 1
50 6 3 1
1 1 1 1
0 0 0 0

Sample Output

success on day 3
failure on day 4
failure on day 7
failure on day 68
success on day 20
failure on day 2

解题报告:

看懂题意后直接模拟。注意怎么才算fail,不是这一整天下来没上升就算fail,而是掉到井底的那一天才算fail。

AC代码:

#include<bits/stdc++.h>using namespace std;int main()
{double h,u,d,f;//井高,爬高,降高,百分比 double curh=0;int day = 0;while(1) {scanf("%lf%lf%lf%lf",&h,&u,&d,&f);double down = u*f*0.01;curh=0,day=0;int flag = 0;if(h == 0 ) break;while(curh <= h) {if(curh < 0) {break;}curh += u;day++;u-=down;if(curh  > h) {flag = 1;break;}curh-=d;}if(flag == 1) {printf("success on day %d\n",day);}else {printf("failure on day %d\n",day);}}return 0 ;
}

【HDU - 1302】The Snail (模拟,水题)相关推荐

  1. 洛谷 1563 玩具谜题——模拟水题

    题目:https://www.luogu.org/problemnew/show/P1563 模拟水题. #include<iostream> #include<cstdio> ...

  2. 【CCCC】L2-027 名人堂与代金券 (25分),模拟水题

    problem L2-027 名人堂与代金券 (25分) 对于在中国大学MOOC(http://www.icourse163.org/ )学习"数据结构"课程的学生,想要获得一张合 ...

  3. 【HDU - 1326】Box of Bricks(模拟水题)

    题干: Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds ...

  4. poj 3095 Linear Pachinko 模拟水题

    题意: 给一个字符串,求小球随机放在上面进洞或到达两边之外的期望. 分析 水题,直接模拟. 代码: //poj 3095 //sep9 #include <iostream> using ...

  5. HDU 6264 Super-palindrome(CCPC2017杭州) 水题

    http://acm.hdu.edu.cn/showproblem.php?pid=6264 题目大意:给定字符串TTT,使得该字符串的每个长度为奇数的子串都是回文串,求至少要修改的字符的数量. 思路 ...

  6. hdu 2041:超级楼梯(水题,递归)

    超级楼梯Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  7. 【HDU - 5585】Numbers (水题,数学,数论)

    题干: There is a number N.You should output "YES" if N is a multiple of 2, 3 or 5,otherwise ...

  8. 【HDU 1889】Reaux! Sham! Beaux!(模拟+水题)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1889 题意:给出一个表,每个国家的石头剪子布的叫法,给两个人用自己国家的语言进行石头剪子布,进行统计,最 ...

  9. HDU 2549 壮志难酬 (水题,但有个小坑!)

    壮志难酬 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  10. 一发模拟水题但是RE,暑假抽个时间改一改、、

    这是我们实验室纳新考试的A题,简单模拟. 话不多说上题干: 哲哲晔晔很难受 Description 哲哲和晔晔最喜欢一起睡懒觉了!可老师又特别喜欢点名,所以每个第一节有课的早晨,他们都会很难受. 因为 ...

最新文章

  1. UVA10296 Jogging Trails(中国邮递员问题)(欧拉回路、一般图最大权匹配 / 状压DP)
  2. numpy 辨异(二) —— np.identity()/np.eye()
  3. PAT(乙级) 1002 写出这个数 (20point(s)) Python
  4. java编写一个程序_计算已知长和宽的长方形的周长,请教一下大佬们,我们java留了一个作业,编写程序,定义一个接口Comput,声明计算周长和面积的方法...
  5. NameNode启动
  6. notepad批量删除html元素,Notepad++几个常用删除类正则表达式汇总(收藏)
  7. struts2和hibernate(2012/2/26)
  8. Halcon图像预处理之灰度形态学
  9. Java基础:如何改变字符串内字符的大小写
  10. CAD图纸加密系统 - CAD2EXE V10.3
  11. 小程序毕设作品之微信校园洗衣小程序毕业设计成品(7)中期检查报告
  12. 使用okhttp下载文件 、传统方式下载文件,简介okhttp使用(Java)
  13. ps滑动鼠标放大缩小
  14. ARM920T中断体系结构
  15. 新浪微博开放平台接入
  16. 阿里云服务器使用xshell连接
  17. 看董事长陈睿11周年演讲,一起了解B站未来的三个使命吧
  18. 河南灵活用工系统开发|灵活用工平台能为企业带来什么?
  19. Android Studio使用签名打包发布APP(安卓生成apk文件)
  20. 北大青鸟 ASP.NET(C#) 视频 全32集

热门文章

  1. 1.6解不等式 1.6.1 平方根不等式
  2. 链表中删除选定结点的优雅操作!
  3. mysql日期可以保存时区_数据库存储时间的时区问题
  4. 上海大学c语言作业答案,《上海大学C语言选择题》.doc
  5. 零基础不建议学前端_web前端培训心得:零基础怎样学好web前端
  6. unique_ptr使用简介
  7. 实例解析linux内核I2C体系结构(2)
  8. Makefile.am
  9. 计算机在材料中的运用结课,计算机在材料科学工程中的应用的结课论文.doc
  10. centos 卸载_CentOS安装mysql