标题:一个爬虫的问题,,原题是英文的
只看楼主
wbq777
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-6-24
结帖率:66.67%
已结贴  问题点数:20 回复次数:15 
一个爬虫的问题,,原题是英文的
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
问下高手噶。。那个虫子是每分钟爬u英寸,每次都要休息1分钟,那时候向掉下d英寸,一共是n英寸,为什么能算出17 19分钟的啊,,我想了下不是20分钟么
搜索更多相关主题的帖子: 英文 process always before 
2011-08-10 15:33
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
得分:5 
这条虫子本身长1英寸,你考虑了没有?

授人以渔,不授人以鱼。
2011-08-10 15:37
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
得分:5 
程序代码:
#include <iostream>
using namespace std;
int main()
{
    int x,y,z;
    while(1)
    {
        int r=0,s=0,t=0;
        cin>>x>>y>>z;
        if(x+y+z==0) break;
        r=y-z;
        s=x-y;
        if(s%r==0)
        {
        t=2*(s/r);
        t+=1;
        }
        else
        {
            t=2*(s/r+1)+1;
        }
        cout<<t<<endl;

    }
    return 0;   
}

                                         
===========深入<----------------->浅出============
2011-08-10 15:40
wbq777
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-6-24
得分:0 
回复 2楼 TonyDeng
额..没有考虑诶。。不过,本身长1英寸的吧。那和总路程除去1英寸一样么?
2011-08-10 15:41
wbq777
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-6-24
得分:0 
回复 3楼 laoyang103
出现输出越界
2011-08-10 15:42
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
得分:10 
不一样的,你画图模拟一下过程,找出症结再说写程序。

授人以渔,不授人以鱼。
2011-08-10 15:44
wbq777
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-6-24
得分:0 
回复 3楼 laoyang103
哦,,妳这个是对的,,不过不大懂诶,能给的C的么
2011-08-10 15:44
wbq777
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2011-6-24
得分:0 
回复 6楼 TonyDeng
哦。。谢了。。那我看看
2011-08-10 15:45
lccwyj
Rank: 4
等 级:业余侠客
帖 子:71
专家分:203
注 册:2011-5-6
得分:0 
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
int sum=(a-2)/(b-c)*2+1;
printf("%d",sum);
2011-08-10 20:26
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
得分:0 
也来凑个热闹
程序代码:
#include<stdio.h>
int main()
{
  int n, u, d;
  while(scanf("%d%d%d", &n, &u, &d), n)
    printf("%d\n", (n - d - 1) / (u - d) + 1);
  return 0;
}

重剑无锋,大巧不工
2011-08-10 22:51



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-347238-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014327 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved