hdu-1049 Climbing Worm

                             Climbing Worm


Problem Description
An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, it slips down d inches. The process of climbing and resting then repeats. How long before the worm climbs out of the well? We'll always count a portion of a minute as a whole minute and if the worm just reaches the top of the well at the end of its climbing, we'll assume the worm makes it out.
Input
There will be multiple problem instances. Each line will contain 3 positive integers n, u and d. These give the values mentioned in the paragraph above. Furthermore, you may assume d < u and n < 100. A value of n = 0 indicates end of output.
Output
Each input instance should generate a single integer on a line, indicating the number of minutes it takes for the worm to climb out of the well.
Sample Input
10 2 1
20 3 1
0 0 0
 
Sample output
십칠
십구
제목: 고도 n, 분당 기어오르는 높이 u, 휴식 시 분당 내려가는 높이를 제시한다.먼저 1분만 올라가고 1분만 쉬세요. 이렇게 유추해서 높이 n까지 올라갈 때까지.제발 몇 분 걸렸어?n=0시에 끝납니다.또 초등학생 수학 문제야, 유목유!!!
#include<iostream>
using namespace std;
int main()
{
	int n,u,d;  //n ,u ,d 
	while(cin>>n>>u>>d)
	{
		if(n==0)   //n=0 
			break;
		int min;   // 
		int dis=0;  // 
		for(min=1;;min++)
		{
			// , 
			if(min%2==0)  
			{
				dis-=d;
			}
			else
			{
				dis+=u;
				if(dis>=n) // n, 
					break;
			}
		}
		cout<<min<<endl;
	}
	return 0;
}

좋은 웹페이지 즐겨찾기