HDU1302 - The Snail

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1302

#include 
using namespace std;
//注意:每天爬的距离比第一天少F%,而不是比前一天 
int main() {
    double h, u, d, f, first;
    while (cin >> h >> u >> d >> f, h) {
        double sum = 0;
        int day = 0, flag = 1;
        first = u * f * 0.01;
        //The distance lost to fatigue is always 10% of 
        //the first day's climbing distance
        sum += u;
        day ++;
        while (sum <= h && flag) {
            sum -= d;
            if (sum < 0) {
                flag = 0;
                cout << "failure on day " << day << endl;
                break;
            }
            u -= first; 
            //由于疲劳而损失的距离始终是第一天攀爬距离的f%
            sum += u;
            day++; 
        }
        if (flag)
            cout << "success on day " << day << endl;
    }
    return 0;
} 

你可能感兴趣的:(HDU1302 - The Snail)