【NOIP2016提高A组模拟9.9】Brothers
来源:互联网 发布:各国工资数据 编辑:程序博客网 时间:2024/05/20 07:58
Description
在遥远的西方有一个古老的王国,国王将他的王国分成了网格状,每一块称之为一个城市。在国王临死前,他将这些城市分给了自己的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场战役之后的城市归属图。
提解
用一个F数组表示i会被谁吃。然后暴力更新每一个点,即可。
代码
var n,r,c,k:longint; a,b:array [0..101,0..101] of integer; tong,f:array [0..101] of integer;procedure init;var i,j:longint;begin fillchar(tong,sizeof(tong),0); readln(n,r,c,k); for i:=1 to r do for j:=1 to c do begin read(a[i,j]); a[i,j]:=a[i,j]+1; inc(tong[a[i,j]]); end; for i:=0 to c+1 do begin a[0,i]:=maxint div 3; a[r+1,i]:=maxint div 3; end; for i:=1 to r do begin a[i,0]:=maxint div 3; a[i,c+1]:=maxint div 3; end; for i:=2 to n do f[i]:=i-1; f[1]:=n;end;procedure main;var l,i,j,x:longint;begin for l:=1 to k do begin for i:=1 to r do for j:=1 to c do begin x:=a[i,j]; b[i,j]:=0; if a[i-1,j]=f[x] then b[i,j]:=a[i-1,j] else if a[i,j-1]=f[x] then b[i,j]:=a[i,j-1] else if a[i+1,j]=f[x] then b[i,j]:=a[i+1,j] else if a[i,j+1]=f[x] then b[i,j]:=a[i,j+1]; if b[i,j]<>0 then begin dec(tong[x]); inc(tong[b[i,j]]); end else b[i,j]:=x; end; for i:=1 to n do if tong[i]=0 then begin j:=(i+1) mod n; if f[j]=0 then j:=(j+1) mod n; f[j]:=i; f[i]:=0; end; a:=b; end;end;procedure print;var i,j:longint;begin for i:=1 to r do begin for j:=1 to c do write(a[i,j]-1,' '); writeln; end;end;begin init; main; print;end.
1 0
- 【NOIP2016提高A组模拟9.9】Brothers
- 【NOIP2016提高A组模拟9.9】Brothers
- Brothers【NOIP2016提高A组模拟9.9】
- 【NOIP2016提高A组模拟9.9】爬山
- 【NOIP2016提高A组模拟9.9】闭门造车
- 【NOIP2016提高A组模拟9.9】爬山
- 【NOIP2016提高A组模拟9.9】总结
- 【NOIP2016提高A组模拟9.9】Crisis
- 【NOIP2016提高A组模拟9.9】Word
- 【NOIP2016提高A组模拟9.9】闭门造车
- 【NOIP2016提高A组模拟9.9】爬山
- Crisis【NOIP2016提高A组模拟9.9】
- 【NOIP2016提高A组模拟9.9】运输妹子
- 【NOIP2016提高A组模拟9.9】运输妹子
- 【NOIP2016提高A组模拟9.9】运输妹子
- 【JZOJ4771】【NOIP2016提高A组模拟9.9】爬山
- 【JZOJ4772】【NOIP2016提高A组模拟9.9】运输妹子
- 【JZOJ4770】【NOIP2016提高A组模拟9.9】闭门造车
- Another Crisis_uva12186_树形dp
- 在bitbucket用git 用法
- Brothers_纪中4764_模拟
- 记录学习java的笔记
- 实用资源集合下载
- 【NOIP2016提高A组模拟9.9】Brothers
- 【Bash百宝箱】Bash简介
- java 7 -3 继承
- java中dynamic web project与web project 的区别
- UI Thread & Worker Thread
- 【jzoj4765】【Crisis】【树形动态规划】
- 【Android 开发入门】Android Studio 下载及安装
- 【Bash百宝箱】shell命令
- bzoj 3669: [Noi2014]魔法森林 link cut tree