HDU1302_Snail【模拟题】【水题】

The Snail

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1488    Accepted Submission(s): 1092

Problem Description

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

Source

Mid-Central USA 1997

题目大意:蜗牛从井底向上爬高,井深H米,早上爬U米,晚上下滑D米,且它

从第二天开始每天疲劳,每天比第一天少F%,问最后第几天能爬出井或者不能爬

出井而失败。

思路:简单模拟,按照题目要求做就可以。

#include<stdio.h>
#include<string.h>

int main()
{
    double H,U,D,F;
    while(~scanf("%lf%lf%lf%lf",&H,&U,&D,&F) && (H||U||D||F))
    {
        int day = 0;
        double distance = 0,S = U*F/100;
        bool flag = true;
        while(1)
        {
            day++;
            distance += U;
            if(distance > H)
                break;
            distance -= D;
            if(distance < 0)
            {
                flag = false;
                break;
            }
            U -= S;
            if(U < 0)
                U = 0;
        }
        if(flag)
            printf("success on day %d\n",day);
        else
            printf("failure on day %d\n",day);
    }

    return 0;
}
时间: 2024-10-24 08:39:38

HDU1302_Snail【模拟题】【水题】的相关文章

4.7-4.9补题+水题+高维前缀和

题目链接:51nod 1718 Cos的多项式  [数学] 题解: 2cosx=2cosx 2cos2x=(2cosx)^2-2 2cos3x=(2cosx)^3-3*(2cosx) 数归证明2cos(nx)能表示成关于2cosx的多项式,设为f(n) f(1)=x,f(2)=x^2-2(其中的x就是2cosx) 假设n=1~k时均成立(k>=3) 当n=k+1时 由cos((k+1)x)=cos(kx)cos(x)-sin(kx)sin(x) cos((k-1)x)=cos(kx)cos(x)

(补题 水题 汇总)四川大学第二届SCUACM新生赛

B-丁姐姐喜欢LCS 原题链接 输入 abc bca wad ad as asd wa aw wa wwa 输出 bc ad as a 解题思路 暴力呀!暴力呀!暴力呀!!!(我真是白学了ORZ) 代码样例 #include <bits/stdc++.h> using namespace std; int main(){ string a,b; while(cin >> a >> b){ bool judge = false; int cnt=0; for(int i=

HDU 5867 Water problem ——(模拟,水题)

我发这题只是想说明:有时候确实需要用水题来找找自信的~ 代码如下: 1 #include <stdio.h> 2 #include <algorithm> 3 #include <string.h> 4 using namespace std; 5 typedef long long ll; 6 7 int num[1000+5] = {0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8,6}; 8 int sum[1000+5]; 9 10

Codeforces 939A题水题

题目链接:http://codeforces.com/problemset/problem/939/A A题 A. Love Triangle time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As you could know there are no male planes nor female planes. However

ZOJ 2819 Average Score 牡丹江现场赛A题 水题/签到题

ZOJ 2819 Average Score Time Limit: 2 Sec  Memory Limit: 60 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 Description Bob is a freshman in Marjar University. He is clever and diligent. However, he is not good at math, especia

hdu - 6276,2018CCPC湖南全国邀请赛A题,水题,二分

题意: 求H的最大值,  H是指存在H篇论文,这H篇被引用的次数都大于等于H次. 思路:题意得,  最多只有N遍论文,所以H的最大值为N, 常识得知H的最小值为0. 所以H的答案在[0,N]之间,二分搜一下,如果满足就提高下限,不满足则降低上限. 嗯就这样!!!! AC code: #include<bits/stdc++.h> using namespace std; int n; vector<int> cc(200005); int main() { bool check(i

hdu4505 小Q系列故事——电梯里的爱情(水题)

Problem Description http://acm.hdu.edu.cn/showproblem.php?pid=4505 细心的同事发现,小Q最近喜欢乘电梯上上下下,究其原因,也许只有小Q自己知道:在电梯里经常可以遇到他心中的女神HR. 电梯其实是个很暧昧的地方,只有在电梯里,小Q才有勇气如此近距离接近女神,虽然觉得有点不自在,但次数多了,女神也习惯了小Q的存在,甚至熟悉到仿佛不说上句话自己也都觉得不合适了.可是,他们的谈话也仅仅限于今天天气不错啊或是你吃了吗之类的,往往在对方微笑点

涨姿势题2_水题_两种解法

Problem Description 涨姿势题就是所谓的优化题,在组队赛中,队伍发现了一题水题,那么应该交给谁去处理?作为处理水题的代码手,应该具备什么样的素养?1,要快,水题拼的就是速度!2,不能卡水题!水题都卡,绝对不是一个代码手的风范!3,不能出错,错一次即罚时20分钟,对于水题来讲是致命的!4,要能看出来一题是水题!没有这条,上面三条都是没有意义的! 如果你希望你成团队中一个合格的代码手,那么这套题是你最好的选择,快AC吧! 本系列即是为了提高水题代码手的素养而准备的!水题经常需要用到

poj 1005:I Think I Need a Houseboat(水题,模拟)

I Think I Need a Houseboat Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 85149   Accepted: 36857 Description Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land,

POJ 3030. Nasty Hacks 模拟水题

Nasty Hacks Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13136   Accepted: 9077 Description You are the CEO of Nasty Hacks Inc., a company that creates small pieces of malicious software which teenagers may use to fool their friends.