HDU1302

题目链接

传送门

题目大意

题目大意是说给出h、u、d、f,分别代表井的高度、白天爬的距离、晚上滑落的距离、疲劳度。问是否能爬出井,给出具体日期(成功或失败)。

解题思路

暴力模拟····注意疲劳度(每次减少的距离)只取决于第一天爬的距离,即per = u * (f / 100.0);还有就
是如果u <= 0 时,当天蜗牛不会爬,但是照常滑落·····

参考代码

#include <functional>  
#include <algorithm>  
#include <iostream>  
#include <fstream>  
#include <sstream>  
#include <iomanip>  
#include <numeric>  
#include <cstring>  
#include <climits>  
#include <cassert>  
#include <complex>  
#include <cstdio>  
#include <string>  
#include <vector>  
#include <bitset>  
#include <queue>  
#include <stack>  
#include <cmath>  
#include <ctime>  
#include <list>  
#include <set>  
#include <map>  

using namespace std;  

typedef long long LL;  
typedef double DB;  
typedef unsigned uint;  
typedef unsigned long long uLL;  

/** Constant List .. **/ //{  

const int MOD = int(1e9)+7;  
const int INF = 0x3f3f3f3f;  
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;  
const DB EPS = 1e-9;  
const DB OO = 1e20;  
const DB PI = acos(-1.0); //M_PI;  

int main()  
{  
    #ifdef ZH  
    freopen("in.txt","r",stdin);  
    #endif  
    double h , u , d , f;  
    while(~scanf("%lf%lf%lf%lf",&h,&u,&d,&f) && h)  
    {  
        if(h == 0)  
            break;  
        int day = 1;  
        double high = 0;  
        double per = u * (f / 100.0);  
        int flag1 = 0 , flag2 = 0;  
        while(high <= h && high >= 0)  
        {  
            if(u > 0)  
                high += u;  
            if(high > h)  
            {  
                flag1 = 1;  
                break;  
            }  
            high -= d;  
            u -= per;  
            if(high < 0)  
            {  
                flag2 = 1;  
                break;  
            }  
            day ++;  
        }  
        if(flag1 == 1)  
            printf("success on day %d\n",day);  
        else if(flag2 == 1)  
            printf("failure on day %d\n",day);  
    }  
}  

暂无评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注

© 2018-2019 惜春令 京ICP备18010644号 网站地图