求对着pascal标程进行讲解——noip2012普及组第二题宝藏
noip2012普及组第二题:宝藏;跪求讲解啊!泪奔,只知道是模拟满分标程如下:vara,b:array[1..10005,0..105]oflongint;n,m,i,...
noip2012普及组 第二题:宝藏;
跪求讲解啊!泪奔,只知道是模拟
满分标程如下:
var a,b:array [1..10005,0..105] of longint; n,m,i,j,k,start,ans:longint;
function gp(c,x,k:longint):longint;
var i,j,all:longint;
begin
all:=0;
for i:=0 to m-1 do if a[c,i]=1 then inc(all);
k:=k mod all;
if k=0 then k:=all;
j:=0;
i:=x;
while 0=0 do begin
if a[c,i]=1 then inc(j);
if j=k then exit(i);
i:=(i+1) mod m;
end;
end;
begin
assign(input,'treasure.in');reset(input);
assign(output,'treasure.out');rewrite(output);
readln(n,m);
for i:= 1 to n do
for j:=0 to m-1 do readln(a[i,j],b[i,j]);
readln(start);
ans:=0;
for i:=1 to n do begin
ans:=(ans+b[i,start]) mod 20123;
start:=gp(i,start,b[i,start]);
end;
writeln(ans);
close(input);close(output);
end.
答好了有追加 展开
跪求讲解啊!泪奔,只知道是模拟
满分标程如下:
var a,b:array [1..10005,0..105] of longint; n,m,i,j,k,start,ans:longint;
function gp(c,x,k:longint):longint;
var i,j,all:longint;
begin
all:=0;
for i:=0 to m-1 do if a[c,i]=1 then inc(all);
k:=k mod all;
if k=0 then k:=all;
j:=0;
i:=x;
while 0=0 do begin
if a[c,i]=1 then inc(j);
if j=k then exit(i);
i:=(i+1) mod m;
end;
end;
begin
assign(input,'treasure.in');reset(input);
assign(output,'treasure.out');rewrite(output);
readln(n,m);
for i:= 1 to n do
for j:=0 to m-1 do readln(a[i,j],b[i,j]);
readln(start);
ans:=0;
for i:=1 to n do begin
ans:=(ans+b[i,start]) mod 20123;
start:=gp(i,start,b[i,start]);
end;
writeln(ans);
close(input);close(output);
end.
答好了有追加 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询