poj1563---蜗牛爬井

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int dayTh;
    float Udis,currentHeight,firstClaim,HeightOfWell,downDis,fagtigue;
    while(scanf("%f %f %f %f",&HeightOfWell,&Udis,&downDis,&fagtigue)!=EOF){
        if(HeightOfWell==0)
            break;
        currentHeight=0;
        firstClaim=Udis;
        dayTh=0;
        while(1){
            currentHeight+=Udis;
            Udis-=fagtigue/100*firstClaim;
            if(Udis<0)
                Udis=0;
            dayTh++;
            if(currentHeight>HeightOfWell){
                printf("success on day %d\n",dayTh);
                break;
            }
            else{
                currentHeight-=downDis;
                if(currentHeight<0)
                    {
                        printf("failure on day %d\n",dayTh);
                        break;
                    }
                }
        }
    }
    return 0;
}

WA过,注意当Udis<0,Udis=0;变量都赋值成float

时间: 2024-08-29 16:59:34

poj1563---蜗牛爬井的相关文章

杭电ACM 蜗牛出井

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 ea

16.10.20 4th 1蛤蟆爬井 2一维数组 3二维数组

摘要 1蛤蟆爬井 2一维数组 3二维数组 例子 井深10米, 蛤蟆白天爬5m,晚上落4米,求几天爬出来. //思路,用循环语句来做,for因为是未知次数所以排除,while 先判断后运行排除, dowhile,先爬在判断所以可以 int gaodu = 0; int tianshu = 0; boolean tianse = true; do{ if(tainse){ //白天爬5米 gaodu+=5; //爬完后改黑天 tianse = false; //天数+1 tianshu +=1; }

蜗牛爬墙

蜗牛爬墙一只蜗牛爬10米高的城墙,早上爬3米,晚上下落2米,问蜗牛多少天可以爬过那10米的城墙? 第一天白天:3米第一天晚上:下落2米    第一天前进:1米第二天白天:1+3米第二天晚上:下落2米    第二天前进:2米......最后登上10米城墙 数据结构分析:初始高度:high=0:            蜗牛爬的高度(变化):int high:白天爬的高度(不变):3:        晚上下落的高度(不变):2:一天爬行高度(不变):1: 蜗牛的高度等于大于10时的那天白天就成功,即n

HPU--1141 蜗牛爬树

1141: 蜗牛爬树 [模拟] 时间限制: 1 Sec 内存限制: 128 MB 提交: 377 解决: 60 统计 题目描述 阿门阿前一棵葡萄树,阿嫩阿嫩绿地刚发芽,蜗牛背著那重重的壳呀,一步一步地往上爬. 想必很多小伙伴都听过这首<蜗牛与黄鹂鸟>,那么现在知道了蜗牛所爬树的高度.蜗牛白天爬一段距离,但是晚上将会下落一段距离. 求蜗牛爬到树顶是在第几天. 输入 每次测试只有一组测试数据. 每一行有三个整数,h,n,m(1≤h,n,m≤1000)分别代表树的高度.蜗牛白天爬的距离.蜗牛晚上下落

【贪心专题】HDU 1049 Climbing Worm (爬井趣题)

链接:click here~~ 题意: 题目大致意思是一个虫子掉在了一个n长度深的井中,然后它每分钟可以爬u长度,然后要休息一分钟,在此期间它会掉下d长度,问最终爬出井需要多久. 简单模拟: 代码: #include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <algorithm> using namespace std; int ma

HDU 1049(蠕虫爬井 **)

题意是一只虫子在深度为 n 的井中,每分钟向上爬 u 单位,下一分钟会下滑 d 单位,问几分钟能爬出井. 本人是直接模拟的,这篇博客的分析比较好一些,应当学习这种分析问题的思路:http://www.cnblogs.com/A--Q/p/5719353.html 代码如下: 1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n,u,d,pos,ans; 6 while(~scanf("%d

1072: 青蛙爬井

题目描述 有一口深度为high米的水井,井底有一只青蛙,它每天白天能够沿井壁向上爬up米,夜里则顺井壁向下滑down米,若青蛙从某个早晨开始向外爬,对于任意指定的high.up和down值(均为自然数),计算青蛙多少天能够爬出井口? 输入 输入3个正整数:high.up和down. 输出 输出一个整数,表示天数.输出单独占一行. 样例输入 10 2 1 样例输出 9 提示 循环模拟.注意,不能简单地认为每天上升的高度等于白天向上爬的距离减去夜间下滑的距离,因为若白天能爬出井口,则不必等到晚上.

第四天总结

今天是第四天,考试了,考的不怎么样,可以说,很不好.满分400分,只考了310??.共4道题,对的就不说了.有一道题,是因为没看清题,得了90,也不说啥了,就说说那一道蜗牛题吧! 这道题是我们小学就见到的蜗牛爬井问题. 我先输入了一个if,如果蜗牛爬的,没有滑下的多,就输出"bye bye".但没想到,如果第一天就能爬完呢?就根本不用滑下来了!所以,错了??. 但我又用了一个循环,设置了if(a>b)而且设置,if(D≤(a-b)(m-1)+a;),这样,一天可爬出来的根本输不出

杭电ACM:A snail(附源码)

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 ea