Title Link: http://vjudge.net/problem/HDU-1302
Analysis: The limitations of this problem are many, one day is divided into day and night. It is not possible to use the rise-fall as a daily change (what if the day goes out?). )。
At the beginning of the initial position to set the double type of 0, I wrote the int type, depressed for half a day.
Be aware that the up distance cannot be negative, even if you are tired.
1#include <cstdio>2#include <cstring>3#include <cmath>4#include <iostream>5#include <algorithm>6#include <string>7#include <cstdlib>8 9 using namespacestd;Ten One intMain () A { - DoubleHeight,up,down,factor,delta; - while(~SCANF ("%LF",&height)) the { - if(height==0) Break; -scanf"%lf%lf%lf",&up,&down,&factor); - intday=0, flag=0; + DoublePlace=0, first=Up ; -Delta= (first*factor*0.01); + for(day=1;; day++) A { at if(up>=0) place+=Up ; - if(place>height) - { -flag=1; - Break; - } inplace-=Down ; - if(place<0) to { +flag=0; - Break; the } * if(up>=0) up-=Delta; $ }Panax Notoginseng if(flag) printf ("success on day%d\n", day); - Elseprintf"failure on day%d\n", day); the } + return 0; A}
(HDU) 1302-the Snail (snail)