zoj 这个就是一个傻逼题目。题目都根本没法看懂。看了人家的解题报告才弄懂什么意思。就是每个元素上下左右四边元素加上这个元素 , 这五个元素和在D数组里找对应码。然后这个对应码再加上当前位置元素判断是否大于3 或着小于0,大于3 取3 ,小于0取0。那么这个结果就是一天后每个块的种群密度。
/*=============================================================================
#
# Author: liangshu - cbam
#
# QQ : 756029571
#
# School : 哈尔滨理工大学
#
# Last modified: 2015-11-05 21:34
#
# Filename: A.cpp
#
# Description:
# The people who are crazy enough to think they can change the world, are the ones who do !
=============================================================================*/
#
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<cctype>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
int main()
{
int t, n;
int d[40], dic[22][22], cnt[22][22];
while(cin>>t){
while(t--){
int day;cin>>day;
for(int i =0; i < 16; i++){
cin>>d[i];
}
memset(cnt, 0, sizeof(cnt));
for(int i = 1; i <= 20; i++){
for(int j = 1; j <= 20; j++){
cin>>cnt[i][j];
}
}
while(day--){
int i, j;
for( i = 1; i <= 20; i++){
for(j = 1; j <= 20; j++){
int k = cnt[i][j];
int t = k + cnt[i - 1][j] + cnt[i + 1][j] + cnt[i][j - 1] + cnt[i][j + 1];
dic[i][j] = t;
}
}
for(i = 1; i <= 20; i++){
for(j = 1; j <= 20; j++){
int v = (cnt[i][j] += d[dic[i][j]]);
if(v > 3){
cnt[i][j] = 3;
}
else if( v < 0){
cnt[i][j] = 0;
}
}
}
}
for(int i = 1; i <= 20; i++){
for(int j = 1; j <= 20; j++){
if(cnt[i][j] == 0){
cout<<".";
}
else if(cnt[i][j] == 1){
cout<<"!";
}
else if(cnt[i][j] == 2){
cout<<"X";
}
else if(cnt[i][j] == 3){
cout<<"#";
}
}
cout<<endl;
}
if(t){
cout<<endl;
}
}
}
return 0;
}