Hangzhou Electric HDU ACM 1302 the Snail

Source: Internet
Author: User

The Snail Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 1783 Accepted Submission (s): 1252


Problem Descriptiona snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun was up and slides down 1 foot in night while sleeping. The snail has a fatigue factor of 10%, which means this on each successive day the snail climbs 10% * 3 = 0.3 feet less th An it does the previous day. (The distance lost to fatigue are always 10% of the first day ' s climbing distance.) On which day does the snail leave the well, i.e., what's the first day during which the snail ' s height exceeds 6 feet? (a day consists of a period of sunlight followed by a period of darkness.) As can see from the following table, the snail leaves the well during the third day.

Day Initial height Distance climbed height after climbing height after Sliding
1 0 3) 3 2
2 2 2.7) 4.7 3.7
3 3.7 2.4 6.1-

Your job is to solve this problem in general. Depending on the parameters of the problem, the snail would eventually either leave the well or slide back to the bottom of The well. (In other words, the snail ' s height would exceed the height of the well or become negative.) You must find off which happens first and on what day.

Inputthe input file contains one or more test cases, each on a line by itself. Each line contains four integers H, U, D, and F, separated to a single space. If H = 0 It signals the end of the input; Otherwise, all four numbers'll be between 1 and inclusive. H is the height of the feet, you are the distance in feet, the snail can climb during the day, and D is the distance In feet so the snail slides down during the night, and F are the fatigue factor expressed as a percentage. The snail never climbs a negative distance. If the fatigue factor drops the snail ' s climbing distance below zero, the snail does not climb at all,. Regardless of the snail climbed, it always slides D feet at night.

Outputfor each test case, output a line indicating whether the snail succeeded (left the well) or failed (slid Bottom) and on. Format the output exactly as shown in the example.

Sample Input
6 3 1 1010 2 1 5050 5 3 1450 6 4 150 6 3 11 1 1 10 0 0 0

Sample Output
Success on day 3failure in day 4failure on day 7failure on day 68success on day 20failure on day 2

Sourcemid-central USA 1997 Fucking eggs! WA countless times! By his brother-in-law! I was bullied by first-year Olympiad numbers. What about IQ?
#include <iostream>using namespace Std;int main () {double H, d,u;double f;while (cin>>h>>u>>d >>F,H) {      double k= (f/100) *u;  int day=0;double high=0;  while (1)  {  if (u>0)  {  high+=u;  day++;  if (high>h)  {     cout<< "success on Day" <<day<<endl;    break;  }  High-=d;  if (high<0)  {cout<< "failure on day" <<day<<endl;  break;}      u-=k;  }  else  {  high-=d;  day++;  if (high<0)  {  cout<< "failure on day" <<day<<endl;  Break;}}}}   return 0;}

Hangzhou Electric HDU ACM 1302 the Snail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.