来源:点击打开链接
这个题目也不是很复杂。一只蜗牛,白天上升一些,晚上下滑一些,每天会因为没有力气而比上一天少爬,求这个蜗牛几天滑到底或者几天滑到顶。简单模拟即可,如果用数学反而麻烦。另外当这个蜗牛上升比下降还快的时候,其实就已经不行了= =#
#include <iostream>
#include <string>
using namespace std;
int main()
{
double high,up,down,factor;
while(cin>>high>>up>>down>>factor)
{
bool succ=0,fail=0;
int needday=1;
double nowpos=0;
double rate=up*(factor/100.0);
if(high==0)
break;
while(nowpos<=high && nowpos>=0)
{
if(up>0)
nowpos+=up;
if(nowpos>high)
{
succ=1;
break;
}
nowpos-=down;
up-=rate;
if(nowpos<0)
{
fail=1;
break;
}
needday++;
}
if(fail==1)
{
cout<<"failure on day "<<needday<<endl;
}
else if(succ==1)
{
cout<<"success on day "<<needday<<endl;
}
}
return 0;
}