UVA 573 The Snail

来源:互联网 发布:网络电视不更新怎么办 编辑:程序博客网 时间:2024/04/27 20:22

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);    }}
0 0