573 The Snail(蜗牛)
The Snail |
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 heightexceeds 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 exactlyas 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
题目大意:
题目中的事例:
一个蜗牛在一个6英尺的井中,它希望爬出井,在日出的时候可以向上爬3英尺,但是在晚上睡觉的时候会下降1英尺。蜗牛有10%疲劳的因素,这意味着在每个连续天蜗牛上爬比前一天少10% 3 = 0.3英尺(并且这个减少的距离一直是第一天上爬的10%)。在第几天蜗牛可以离开井?
天数 | 初始高度 | 白天攀爬距离 | 攀爬之后的高度 | 下落之后的高度 |
1 | 0' | 3' | 3' | 2' |
2 | 2' | 2.7' | 4.7' | 3.7' |
3 | 3.7' | 2.4' | 6.1' | - |
在这里我们可以看见第三天蜗牛成功了。
现在任务是解决蜗牛爬井的问题。根据问题的参数,蜗牛最终是爬出井还是落回井底(换句话就是,蜗牛哪天高度超过井的高度,或者是负值),一定要指出这发生的那天。
输入:H:井的高度,U:蜗牛攀爬距离,D:蜗牛下落距离,F:疲劳因素=F%;
假设第i天之后还没有成功或者失败,那么该天攀爬距离是up[i-1] - F%*U; 下落距离依旧是D
注意点:
1. 在本题注意的地方,就是一组数据结束的标志是高度超过井高或者为负值!!!
2. 当然,每次攀爬后,就立即判断是否高出井!!!
3. 每天攀爬距离不能为负值,为负值的时候,令up=0;
4. 注意:解题的时候每天攀爬和攀爬距离都用double型
代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h> int main(){
int h, u, d, f, day;
double up, down, change, height; while(~scanf("%d%d%d%d", &h,&u,&d,&f)&&(h||u||d||f)){
up = u;
down = d;
change = (1.0*f)/100*up;
day = 0;
height = 0;
while(height>=0&&height<=h){
day++;
height += up;
if(height>h) break;
height -= down; up -= change;
if(up <= 0)
up = 0;
}
if(height>h)
printf("success on day %d\n", day);
else
printf("failure on day %d\n", day);
}
return 0;
}
573 The Snail(蜗牛)的更多相关文章
- HDOJ 1302(UVa 573) The Snail(蜗牛爬井)
Problem Description A snail is at the bottom of a 6-foot well and wants to climb to the top. The sna ...
- UVa 573 - The Snail
题目大意:有一只蜗牛位于深一个深度为h米的井底,它白天向上爬u米,晚上向下滑d米,由于疲劳原因,蜗牛白天爬的高度会比上一天少f%(总是相对于第一天),如果白天爬的高度小于0,那么这天它就不再向上爬,问 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- 【托业】【新托业TOEIC新题型真题】学习笔记11-题库六-P7
1.scam [skæm] n.骗局; 诡计; <美俚>诓骗; 故事;vt.欺诈; 诓骗; 2.interpersonal adj.人与人之间的; 人际的; 人与人之间的关系的; 涉及人与 ...
- Volume 1. Maths - Misc
113 - Power of Cryptography import java.math.BigInteger; import java.util.Scanner; public class Main ...
- [USACO5.2]蜗牛的旅行Snail Trails(有条件的dfs)
题目描述 萨丽·斯内尔(Sally Snail,蜗牛)喜欢在N x N 的棋盘上闲逛(1 < n <= 120). 她总是从棋盘的左上角出发.棋盘上有空的格子(用“.”来表示)和B 个路障 ...
- 洛谷——P1560 [USACO5.2]蜗牛的旅行Snail Trails
P1560 [USACO5.2]蜗牛的旅行Snail Trails 题目描述 萨丽·斯内尔(Sally Snail,蜗牛)喜欢在N x N 的棋盘上闲逛(1 < n <= 120). 她总 ...
- 洛谷 P1560 [USACO5.2]蜗牛的旅行Snail Trails(不明原因的scanf错误)
P1560 [USACO5.2]蜗牛的旅行Snail Trails 题目描述 萨丽·斯内尔(Sally Snail,蜗牛)喜欢在N x N 的棋盘上闲逛(1 < n <= 120). 她总 ...
- 洛谷 P1560 [USACO5.2]蜗牛的旅行Snail Trails
题目链接 题解 一看题没什么思路.写了个暴力居然可过?! Code #include<bits/stdc++.h> #define LL long long #define RG regi ...
随机推荐
- (转)dedecms代码详解 很全面
dedecms代码研究(1)开篇dedecms 相信大家一定都知道这个cms 系统,功能比较强大,有比较完善的内容发布,还有内容静态化系统,还有就是它有自己独特的标签系统和模板系统.而模板系统也是其他 ...
- c# 网站发布
.net 网站发布简单步骤: 1.选择需要发布的网站,右击->发布 1)配置文件:可以任意新建文件配置名 2)连接: 发布方法选择系统文件:选择目标位置,任意新建一个位置即可. 3)设置:选择D ...
- ASP.NET MVC中的模型绑定
模型绑定的本质 任何控制器方法的执行都受action invoker组件(下文用invoker代替)控制.对于每个Action方法的参数,这个invoker组件都会获取一个Model Binder ...
- Django filter中用contains 在mysql中的问题
用PYTHON ,DJANGO 做站,在通常的情况下,需要用到 orM 的查询方法,比如object.filter(tag__contains='keywords').... 在这种情况下,如果你跟踪 ...
- C题
C - C Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description Ass ...
- 我的sublime常用快捷键
sublime一般被应用于前端开发,在实际开发中,我们常用的sublime快捷键有哪些呢?这里汇总一下,常用的排在前面. 常用快捷键 Ctrl+Shift+P:打开命令面板 Ctrl+D:选择重复单词 ...
- 洛谷 P1331 海战
传送门 题解:由于船是方形的,所以比较简单.但是考试的时候跪了,orz.忘了考虑类似一圈井号中间有一摊水. 可以只考虑这个点上方和左边点的情况,这样分为四种情况.一种是左边是一滩水, ...
- 畅谈Spring设计哲学
自己从学习编程开始到现在有一个习惯:一直喜欢把软件开发中的技术和思路放到实际生活中去类比考虑.自己平常也喜欢开一些关于软件哲学的书籍,事实证明这些书籍对自己的学习新技术很有很大的帮助.数学是一切学科的 ...
- Vim记录
Command Mode下: . 代表当前行 % 代表所有行 $ 代表结束行 :1,$normal i# 全部行前加#,同下 :%normal i# :read ! cd /usr/bin/; ...
- 突然间,对JAVA也找到点感觉了。
书上没有那段代码,我自己修修补补弄完全了呢.... 就是感觉体系有点宏大,不要急,慢慢玩~!~~ 这个世界很精彩哟~~: QuizCard.java package QuizCard.sky.com; ...