這個題目也不是很復雜。一只蝸牛,白天上升一些,晚上下滑一些,每天會因為沒有力氣而比上一天少爬,求這個蝸牛幾天滑到底或者幾天滑到頂。簡單模擬即可,如果用數學反而麻煩。另外當這個蝸牛上升比下降還快的時候,其實就已經不行了= =#
[cpp]
#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;
}
#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;
}