[HDU] [1302] The Snail

Problem Description

Loading...

Problem Analysis

The snail climbing out of a well problem
What is different this time is that fatigue is included
The climbing distance decreases every day
u-=f
(Note that it is not f% of the current distance that is subtracted, but f% of the initial distance)

Simulate this process
and just add out-of-bounds checks along the way

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<stdio.h>
int main() {
	double h;
	while(scanf("%lf",&h),h) {
		double u,d,f;
		scanf("%lf %lf %lf",&u,&d,&f);
		int cnt=1;
		double t=0;
		f=f/100.0*u;
		while(1) {
			t+=u;
			if(t>h)
				break;
			t-=d;
			if(t<0)
				break;
			u-=f;
			cnt++;
		}
		if(t<0)
			printf("failure on day %d\n",cnt);
		else
			printf("success on day %d\n",cnt);
	}
	return 0;
}

Problem link: 【HDU】[1302]The Snail

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...