【NOIP2016提高A组模拟9.9】Brothers

编程入门 行业动态 更新时间:2024-10-18 10:29:11

【NOIP2016提高A组模拟9.9】<a href=https://www.elefans.com/category/jswz/34/1758457.html style=Brothers"/>

【NOIP2016提高A组模拟9.9】Brothers

在遥远的西方有一个古老的王国,国王将他的王国分成了网格状,每一块称之为一个城市。在国王临死前,他将这些城市分给了自己的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
保证数据合法

比赛时の想法

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

贴代码

varf,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;
beginreadln(n,r,c,k);for i:=1 to r dobeginfor j:=1 to c dobeginread(g[i,j]);inc(g[i,j]);end;readln;end;
end;
begininit;for i:=1 to n-1 do t[i]:=i+1;t[n]:=1;f:=g;for x:=1 to k dobeginfor i:=1 to r dofor j:=1 to c dobeginfor l:=1 to 4 doif (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]]) thenf[i+s[l,1],j+s[l,2]]:=g[i,j];end;g:=f;end;for i:=1 to r dobeginfor j:=1 to c-1 do write(f[i,j]-1,' ');writeln(f[i,c]-1);end;
end.

更多推荐

【NOIP2016提高A组模拟9.9】Brothers

本文发布于:2024-02-06 15:49:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1749898.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Brothers

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!