UVA 573 The Snail

UVA-573

题意:蜗牛白天往上爬,晚上往下滑,并且每天往上爬的距离会按第一天的一定比例递减,求蜗牛能不能爬出去,能爬出去是在第几天,不能的话在第几天触底。
解题思路:暴力模拟,白天爬完判断出没出去,晚上下滑判断触没触底,爬出去的条件是爬的高度 > h。触底条件是爬的高度 < 0。白天爬高的距离最小是0,不会负的。

/*************************************************************************
    > File Name: UVA-573.cpp
    > Author: Narsh
    > 
    > Created Time: 2016年07月14日 星期四 15时12分33秒
 ************************************************************************/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int h,u,d,f;
int main () {
    while (scanf("%d%d%d%d",&h,&u,&d,&f) && h+u+d+f) {
        double l = u, now = u;
        int day=0;
        while (l >= 0) {
            day++;
            if ( l > h ) break;
            l -= d;
            now = now - (double) f/100.0 * (u*1.00);
            if (now < 0) now = 0;
            if (l < 0) break;
            l += now;
        }
        if (l > h) printf("success on day %d\n",day);
        else printf("failure on day %d\n",day);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值