您的位置:首页 > 其它

【NOIP2016提高A组模拟9.9】Brothers

2016-09-12 21:33 465 查看
在遥远的西方有一个古老的王国,国王将他的王国分成了网格状,每一块称之为一个城市。在国王临死前,他将这些城市分给了自己的N个儿子(编号为0到N-1)。然而这N个王子的关系不是很好,0讨厌1,1讨厌2,2讨厌3……N-1讨厌0。

在国王死后,这种不好的关系使得王子之间爆发了战争。战斗只会在相邻的两个城市之间爆发(共有一条边称之为相邻),并且只有当A讨厌B时,A才会对B发起战斗,结果必定是A获得这次战斗的胜利。当一方胜利后,他所进攻的城市就会变成进攻方的。许多战斗是同时发生的,我们称之为一场战役。当多场战役发生之后,剩下的王子将不再发生战争。

例如,如果有3个王子,那么战斗过程如下所示:



Input

第一行输入4个数,N,R,C,K。有N个王子,王国分为R*C的网格图。询问K场战役之后的城市归属图。

下面R行,每行C个数字,表示一开始城市的归属。

Output

R行C列,表示K场战役之后的城市归属图。

Sample Input

Brother1.in

3 4 4 3

0 1 2 0

1 0 2 0

0 1 2 0

0 1 2 2

Brother2.in

4 2 3 4

1 0 3

2 1 2

Brother3.in

8 4 2 1

0 7

1 6

2 5

3 4

Sample Output

Brother1.out

2 2 2 0

2 1 0 1

2 2 2 0

0 2 0 0

Brother2.out

1 0 3

2 1 2

Brother3.out

7 6

0 5

1 4

2 3

Data Constraint

2<=N<=100

2<=R,C<=100

1<=K<=100

保证数据合法

比赛时の想法

好久没见到这么难(撒币)的题目了,模拟就好了啊

贴代码

var
f,g:array[0..105,0..105]of longint;
s:array[1..4,1..2]of longint=((-1,0),(1,0),(0,1),(0,-1));
t:array[0..105]of longint;
i,j,k,l,n,r,c,x:longint;
procedure init;
begin
readln(n,r,c,k);
for i:=1 to r do
begin
for j:=1 to c do
begin
read(g[i,j]);
inc(g[i,j]);
end;
readln;
end;
end;
begin
init;
for i:=1 to n-1 do t[i]:=i+1;
t
:=1;
f:=g;
for x:=1 to k do
begin
for i:=1 to r do
for j:=1 to c do
begin
for l:=1 to 4 do
if (i+s[l,1]>0) and (i+s[l,1]<=r) and (j+s[l,2]>0) and (j+s[l,2]<=c) and (t[g[i,j]]=g[i+s[l,1],j+s[l,2]]) then
f[i+s[l,1],j+s[l,2]]:=g[i,j];
end;
g:=f;
end;
for i:=1 to r do
begin
for j:=1 to c-1 do write(f[i,j]-1,' ');
writeln(f[i,c]-1);
end;
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: