2017年11月04日普及组 Biotech
Description
Bob 發現了一群有趣的細胞。
這群細胞排列成一個 n × m 的矩陣。每個細胞有兩個狀態:放電狀態和平靜
狀態。它們每秒鐘都會按以下的規則轉換狀態:
首先我們定義,一個細胞的鄰居為它周圍的 8 個細胞。同時設 k 為某一個細
胞的處于放電狀態的鄰居的個數。
若 k < 2,則這個細胞在下一秒因電量不足而變為/保持平靜狀態。
若 k = 2,則這個細胞在下一秒保持原來的狀態。
若 k = 3,則這個細胞在下一秒因得到充足的電量而變為/保持放電狀態。
若 k > 3,則這個細胞在下一秒因過載而變為/保持平靜狀態。
Bob 觀察了這些細胞現在所處于的狀態。他想預測 t 秒后這些細胞的狀態。
Input
第一行 3 個正整數 n,m,t。
接下來 n 行,每行一個長度為 m、只包含 01 的字符串,表示每個細胞的初
始狀態。’1’ 表示放電狀態,’0’ 表示平靜狀態。
Output
輸出 n 行,每行一個長度為 m、只包含 01 的字符串,表示每個細胞的 t 秒
后的狀態。’1’ 表示放電狀態,’0’ 表示平靜狀態。
Sample Input
4 4 4
0100
0010
1110
0000
Sample Output
0000
0010
0001
0111
Hint
對于 100% 的數據,1 ≤ n,m ≤ 100,0 ≤ t ≤ 100。
程序:
var n,m,t,i,j,w,k:longint; a:array[-1..101,-1..101]of char; f:array[-1..101,-1..101]of longint;procedure work; var i,j:longint; beginfor i:=1 to n dofor j:=1 to m doif f[i,j]=1 then a[i,j]:='1' else a[i,j]:='0'; end;beginassign(input,'biotech.in');reset(input);assign(output,'biotech.out');rewrite(output);readln(n,m,t);for i:=1 to n dobeginfor j:=1 to m doread(a[i,j]);readln;end;for w:=1 to t dobeginfillchar(f,sizeof(f),0);for i:=1 to n dofor j:=1 to m dobegink:=0;if a[i-1,j-1]='1' then inc(k);if a[i-1,j]='1' then inc(k);if a[i-1,j+1]='1' then inc(k);if a[i,j-1]='1' then inc(k);if a[i,j+1]='1' then inc(k);if a[i+1,j-1]='1' then inc(k);if a[i+1,j]='1' then inc(k);if a[i+1,j+1]='1' then inc(k);if k<2 then f[i,j]:=0 elseif k=2 then f[i,j]:=ord(a[i,j])-ord('0') elseif k=3 then f[i,j]:=1 elseif k>3 then f[i,j]:=0;end;work;end;for i:=1 to n dobeginfor j:=1 to m dowrite(a[i,j]);writeln;end;close(input);close(output); end.轉載于:https://www.cnblogs.com/YYC-0304/p/9500027.html
總結
以上是生活随笔為你收集整理的2017年11月04日普及组 Biotech的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 201711月04日普及组 Array
- 下一篇: 2017年11月01日普及组 I Lik