爬动的蠕虫

Description

一条蠕虫长度为1厘米,在一口深度为n厘米的井底。已知蠕虫每分钟可以向上爬u厘米,但必须休息1分钟后才能接着往上爬。在休息的过程中,蠕虫又下滑了d厘米。这样反复进行上爬和下滑过程,请求出蠕虫需要多少时间才能爬出井。

假定:

1)初始时蠕虫趴在井底(高度为0);

2)上爬过程中,蠕虫头部到达井的顶部就算出井;

3)计算时间时,不足一分钟按一分钟计算。

Input

测试数据有多组,每组一行3个数据,第一个表示井深n(0<n<1000),第二个表示蠕虫每分钟上爬距离u(0<u<1000),第三个表示蠕虫每次休息下滑距离d(0<d<1000)。

Output

对应每组输入数据有一行输出数据,当蠕虫能够从深井逃出时,输出其所需要的时间(分种数);当蠕虫不能从深井逃出时,输出提示信息:"The worm can't escape from the well."。

Sample Input

52 50 5
20 67 17
71 37 37
83 40 24
78 67 8
56 12 25
4 37 7

Sample Output

3
1
The worm can't escape from the well.
7
3
The worm can't escape from the well.
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
    int n,u,d,i=0,a[100001]={0},j;
    while(scanf("%d %d %d",&n,&u,&d)!=EOF)
    {
        if(d<u||(u>=n))
        {
            while(n>0)
            {
                n=n-u;
                a[i]++;
                if(n<=0)
                    break;
                else
                {
                    n=n+d;
                    a[i]++;
                }
                 
            }
        }
        i++;
    }
    j=0;
    while(j<i)
    {
        if(a[j]!=0)
            printf("%d\n",a[j]);
        else
            printf("The worm can't escape from the well.\n");
        j++;
    }
    return 0;
}

1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值