题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1302
思路:直接按着题目意思模拟就行了。。。
View Code
1 #define _CRT_SECURE_NO_WARNINGS 2 #include<iostream> 3 #include<cstdio> 4 #include<cmath> 5 using namespace std; 6 7 int main(){ 8 double h,u,d,f; 9 while(~scanf("%lf",&h)&&h){ 10 scanf("%lf%lf%lf",&u,&d,&f); 11 int day=0; 12 bool flag=true; 13 double dist=0,s=u*f/100; 14 while(1){ 15 day++; 16 dist+=u; 17 if(dist>h)break; 18 dist-=d; 19 if(dist<0){flag=false;break;}; 20 u-=s; 21 if(u<0)u=0; 22 } 23 if(flag){ 24 printf("success on day %d\n",day); 25 }else 26 printf("failure on day %d\n",day); 27 } 28 return 0; 29 }