Chinaunix首页 | 论坛 | 博客
  • 博客访问: 41508
  • 博文数量: 71
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 726
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-24 08:29
文章分类

全部博文(71)

文章存档

2015年(71)

我的朋友

分类: Java

2015-02-17 23:07:53

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
17
19
 

Source
East Central North America 2002
 

  1. //2.1.1
  2. import java.util.Scanner;

  3. public class Main {

  4.     public static void main(String[] args) {
  5.         int n, u, d;
  6.         Scanner input = new Scanner(System.in);
  7.         while (input.hasNext()) {
  8.             n = input.nextInt();
  9.             u = input.nextInt();
  10.             d = input.nextInt();
  11.             if (n == 0 || d >= u || n >= 100)
  12.                 break;
  13.             int t = ((n - u) / (u - d));
  14.             if (t * (u - d) < n - u)
  15.                 t++;
  16.             t *= 2;
  17.             t++;
  18.             System.out.println(t);
  19.         }
  20.     }
  21. }


阅读(169) | 评论(0) | 转发(0) |
0

上一篇:ACM Steps-Section One

下一篇:Box of Bricks

给主人留下些什么吧!~~