水题,直接模拟就可解决。不过有几点需要注意:
1、如果刚好到达顶端,不算成功,他还会滑下来(坑爹呢。。。)
2、如果刚好到达底部,也还没结束,需要继续进行,知道攀爬高度为负数(也是坑。。。)
3、注意数据类型。
其他的没什么好说了~~
#include<iostream>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;
const int MAX = 100100;
int main()
{
double h,u,d,f,cur;
while(cin>>h>>u>>d>>f && h)
{
double cur = 0;
int day = 0;
double dd = u*f*0.01;
while(cur<h)
{
if(u>0) cur += u;
if(cur>h) {day++; break;}
cur -= d;
if(cur<0) {day++; break;}
if(u>0) u -= dd;
day++;
}
if(cur<0) cout<<"failure on day "<<day<<endl;
else cout<<"success on day "<<day<<endl;
}
return 0;
}