| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1289 人关注过本帖
标题:这个题目该怎么做.翻译一下.
取消只看楼主 加入收藏
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
结帖率:50%
收藏
 问题点数:0 回复次数:5 
这个题目该怎么做.翻译一下.

A long, linear field has N (1 <= N <= 1,000) clumps of grass at unique integer locations on what will be treated as a number line.Think of the clumps as points on the number line.

Bessie starts at some specified integer location L on the number line (1 <= L <= 1,000,000) and traverses the number line in the two possible directions (sometimes reversing her direction) in order to reach and eat all the clumps. She moves at a constant speed (one unit of distance in one unit of time), and eats a clump instantly when she encounters it.

Clumps that aren't eaten for a while get stale. We say the "staleness" of a clump is the amount of time that elapses from when Bessie starts moving until she eats a clump. Bessie wants to minimize the total staleness of all the clumps she eats.

Find the minimum total staleness that Bessie can achieve while eating all the clumps.

Input
* Line 1 : Two space-separated integers: N and L.
* Lines 2..N+1: Each line contains a single integer giving the position P of a clump (1 <= P <= 1,000,000).


Output
* Line 1: A single integer: the minimum total staleness Bessie can achieve while eating all the clumps.

Sample Input


4 10
1
9
11
19


Sample Output


44

搜索更多相关主题的帖子: 翻译 
2006-10-26 23:10
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

楼上的大哥,帮忙翻下了.


倚天照海花无数,流水高山心自知。
2006-10-26 23:49
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

一块长为N(1<=N<=1000)且被当作由唯一一组数字标示的数字草田。在这个数线上,每一个草块被看成是一个点。
贝西在草田上的某个特定位置(L,1 <= L <= 1,000,000)出发。并且在走这条数字线时允许走两个方向(有时要掉转它的方向)为了够着并且吃完所有的草地。她是以匀速前进的(单位时间单位距离)当她遇到草地时就吃草。
没被吃掉的草会变质。我们说的陈年旧草是指从贝西开始走动到吃完这块草地所需的时间。贝西想她吃完所有草的陈旧时间之和最少。

/*自己瞎翻译出来了,可是做的是错误的*/


倚天照海花无数,流水高山心自知。
2006-10-27 17:29
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

/*赋上自己写的,大家帮着看一下,看哪里不符题意*/

#include<stdio.h>
#include<math.h>
typedef struct {
long data;
int flag;
}Blink;

Blink a[1000];
int Find_Min(Blink *a,int n,long m) //返回求的最小值
{
int k,i=0;
long t,min;
while(i<n&&a[i].flag==1)
{
i++;
}
//printf("%d\n",i);
if(a[i].data>m)
{
min=a[i].data-m;
}
else
{
min=m-a[i].data;
}
k=i;
i++;
while(i<n)
{
if(a[i].flag==0)
{
if(m>a[i].data)
{
t=m-a[i].data;
}
else
{
t=a[i].data-m;
}
if(min>t)
{
min=t;
k=i;
}
}
i++;
}
return(k);
}

long Sum(Blink *a,int n,long l)
{
long sum=0,num,t=0;
int i=0,k;
num=l;
while(i<n)
{
k=Find_Min(a,n,num);
a[k].flag=1;
//printf("%d :",k);
if(num>a[k].data)
{
t+=num-a[k].data;
}
else
{
t+=a[k].data-num;
}
//printf("%ld\n",t);
sum+=t;
num=a[k].data;
i++;
}
return(sum);
}

int main()
{
int i,n;
long l;
scanf("%d%ld",&n,&l);
for(i=0;i<n;i++)
{
scanf("%ld",&a[i].data);
a[i].flag=0;
}
printf("%ld\n",Sum(a,n,l));
return(0);
}


倚天照海花无数,流水高山心自知。
2006-10-27 17:30
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
以下是引用cwande在2006-10-27 19:08:46的发言:

给你组数据:
5 30
4 21 28 35 36
你得到的答案是114.
但事实上还有更优的.
30->35->36->28->21->4
5+6+14+21+38=84
你可以说一下你的算法,
不过偶觉得这道题还是需要用动态规划解

我也觉得.我用贪心算法.每次选定离当前位置的最小距离.直到每个地方都遍历过.
动态规划刚学,还没理解好.
能不能给个代码?

倚天照海花无数,流水高山心自知。
2006-10-27 20:49
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
以下是引用我不是郭靖在2006-10-27 19:31:41的发言:

没看懂

4 10
1
9
11
19


10->9->11->19->1
1+3+11+29=44

为什么不是1+2+8+18呢

如果你看懂题目的话就知道了.我们说的陈年旧草是指从贝西开始走动到吃完这块草地所需的时间。


倚天照海花无数,流水高山心自知。
2006-10-27 20:50
快速回复:这个题目该怎么做.翻译一下.
数据加载中...
 
   



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

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