1.2.1Climbing Worm(附翻译)

Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5750 AcceptedSubmission(s): 3389

Problem Description

An inch worm is at the bottom of a well ninches deep. It has enough energy to climb u inches every minute, but then hasto rest a minute before climbing again. During the rest, it slips down dinches. The process of climbing and resting then repeats. How long before theworm climbs out of the well? We'll always count a portion of a minute as awhole minute and if the worm just reaches the top of the well at the end of itsclimbing, we'll assume the worm makes it out.

一英寸蠕虫在深井的底部。 它有足够的能量每分钟爬上u英寸,但在再次爬升之前需要休息一分钟。 在休息期间,它会滑下餐桌。 然后攀爬和休息的过程重复。 在蠕虫爬出井之前多久? 我们总是将一分钟的一小部分计为一分钟,如果蠕虫在爬坡结束时刚刚到达井顶,我们就会认为蠕虫将其排除。

Input

There will be multiple problem instances.Each line will contain 3 positive integers n, u and d. These give the valuesmentioned in the paragraph above. Furthermore, you may assume d < u and n< 100. A value of n = 0 indicates end of output.

将会有多个问题实例。每行将包含3个正整数n,u和d。 这些给出了上面段落中提到的值。 此外,您可以假设d <u和n <100。n = 0的值表示输出结束。

Output

Each input instance should generate asingle integer on a line, indicating the number of minutes it takes for theworm to climb out of the well.

每个输入实例应该在一行上生成一个整数,表示蠕虫爬出井所需的分钟数。


10 2 1
20 3 1
0 0 0

Sample Output

17
19

本题解题难度在于在攀爬过程中还不断下滑,而且需要额外注意并不是每次爬都有一次下滑,例如第一个实例当爬到8的位置再往上爬2就直接出去了,a为井深,b是速度,c是下滑距离,采用的方法就是以a-b的距离除以b-c的速度因为是自动取整,所以要是有余数就+1,这算的是爬的次数,因为每次爬一上一滑两秒所以*2,后面+1是因为前面路程-b了(写晕了,也不知道咋解释,手动捂脸)

c++

#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	while(cin>>a>>b>>c&&a!=0){
		if((a-b)%(b-c)!=0){
			d=((a-b)/(b-c)+1)*2+1;
		}else{
			d=((a-b)/(b-c))*2+1;
		}
		cout<<d<<endl;
	}
	return 0;
}

运行截图



猜你喜欢

转载自blog.csdn.net/zhen921/article/details/80229298
今日推荐