讨论 / 无语,哪位大牛改改错
rectangle 2011-08-14 20:57:00
点我顶贴 收藏 删除
展示一下我的代码,请大牛过目并指出错误

program rq636;

const maxn=1000000;

var a:array[0..1000,1..1001] of longint;

f:array[0..8,1..1001] of longint;

n:longint;

procedure init;

var i,j,k:longint;

begin

readln(n);

for i:=0 to 1000 do

for j:=1 to 1001 do a[i,j]:=maxn;

for i:=1 to n do read(a[0,i]);

readln;

for i:=1 to n do read(a[i,n+1]);

readln;

for i:=1 to n do

begin

for j:=1 to n do read(a[i,j]);

readln;

end;

for i:=1 to n do a[i,i]:=maxn;

end;

procedure work;

var

i,j,k,ans:longint;

begin

for i:=0 to 8 do

for j:=0 to 1001 do f[i,j]:=maxn;

for j:=1 to n do f[1,j]:=a[0,j];

for i:=2 to 8 do

for j:=1 to n+1 do

for k:=1 to n do

if f[i-1,k]+a[k,j]<f[i,j] then f[i,j]:=f[i-1,k]+a[k,j];

ans:=maxn;

for i:=1 to n+1 do if f[8,i]<ans then ans:=f[8,i];

writeln(ans);

end;

begin

init;

work;

end.

#1 wyl8899@2011-08-06 21:18:00
回复 删除
......

你的答案难道不应该是f[8,n+1]么.. 第8步必须是终点..你还想到哪去..

#2 rectangle@2011-08-07 17:15:00
回复 删除
回复 沙发wyl8899 的帖子

谢谢你的提醒,但是错的实际上是初始化。f数组的范围[0..8,1..1001],而我

for i:=0 to 8 do

for j:=0 to 1001 do f[i,j]:=maxn;

那时候fpc有问题,这个没有检查出来,害我白交了一次。但改了只后只有60分。

还请大牛过目

#3 rectangle@2011-08-07 17:16:00
回复 删除
这是我改后的程序,只有60分。

program rq636;

const maxn=1000000;

var a:array[0..1000,1..1001] of longint;

f:array[0..8,1..1001] of longint;

n:longint;

procedure init;

var i,j,k:longint;

begin

readln(n);

for i:=0 to 1000 do

for j:=1 to 1001 do a[i,j]:=maxn;

for i:=1 to n do read(a[0,i]);

readln;

for i:=1 to n do read(a[i,n+1]);

readln;

for i:=1 to n do

begin

for j:=1 to n do read(a[i,j]);

readln;

end;

for i:=1 to n do a[i,i]:=maxn;

end;

procedure work;

var

i,j,k,ans:longint;

begin

for i:=0 to 8 do

for j:=1 to 1001 do f[i,j]:=maxn;

for j:=1 to n do f[1,j]:=a[0,j];

for i:=2 to 8 do

for j:=1 to n+1 do

for k:=1 to n do

if f[i-1,k]+a[k,j]<f[i,j] then f[i,j]:=f[i-1,k]+a[k,j];

writeln(f[8,n+1]);

end;

begin

init;

work;

end.

#4 wjltz@2011-08-07 23:15:00
回复 删除
pascal都是60分....
#5 rectangle@2011-08-08 17:02:00
回复 删除
回复 地板wjltz 的帖子

为什么呢??

#6 lxl@2011-08-12 03:55:00
回复 删除
回复 地下室rectangle 的帖子

Pascal的读入效率比c与c++慢得多,

所以大数据读入就超时。

而且RQ的评测机......

超时一个点,下面的三个点全错......

P.S:竞赛时只写了一个搜索,还错

其实此题动归不是太难

状态: Unaccepted

测评机: Xeond[6]

得分: 60分

提交日期: 2011-8-12 19:07:00

有效耗时: 735毫秒

测试结果1: 通过本测试点|有效耗时172ms

测试结果2: 通过本测试点|有效耗时47ms

测试结果3: 通过本测试点|有效耗时156ms

测试结果4: 通过本测试点|有效耗时156ms

测试结果5: 通过本测试点|有效耗时157ms

测试结果6: 选手程序运行超过时限

测试结果7: 测试结果错误.错误结果为:219

正确结果应为:5

测试结果8: 测试结果错误.错误结果为:219

正确结果应为:10

测试结果9: 测试结果错误.错误结果为:219

正确结果应为:8

测试结果10: 通过本测试点|有效耗时47ms

#7 wjltz@2011-08-13 02:43:00
回复 删除
LS正解
#8 戰魂@2011-08-13 07:01:00
回复 删除
100分

pascal应该有100分

#9 阮鹏博@2011-08-13 08:24:00
回复 删除
100分

pascal应该有100分

#10 阮鹏博@2011-08-13 08:25:00
回复 删除
100

100才对啊

查看更多回复
提交回复