ZOJ Problem Set - 3804 YY's Minions
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5336
比较简单的模拟题,题意也很好理解。
1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <vector> 5 #include <cstring> 6 #include <string> 7 #include <algorithm> 8 #include <string> 9 #include <set> 10 #include <functional> 11 #include <numeric> 12 #include <sstream> 13 #include <stack> 14 #include <map> 15 #include <queue> 16 17 #define CL(arr, val) memset(arr, val, sizeof(arr)) 18 19 #define ll long long 20 #define inf 0x7f7f7f7f 21 #define lc l,m,rt<<1 22 #define rc m + 1,r,rt<<1|1 23 #define pi acos(-1.0) 24 25 #define L(x) (x) << 1 26 #define R(x) (x) << 1 | 1 27 #define MID(l, r) (l + r) >> 1 28 #define Min(x, y) (x) < (y) ? (x) : (y) 29 #define Max(x, y) (x) < (y) ? (y) : (x) 30 #define E(x) (1 << (x)) 31 #define iabs(x) (x) < 0 ? -(x) : (x) 32 #define OUT(x) printf("%I64d\n", x) 33 #define lowbit(x) (x)&(-x) 34 #define Read() freopen("a.txt", "r", stdin) 35 #define Write() freopen("b.txt", "w", stdout); 36 #define maxn 1000000000 37 #define N 55 38 using namespace std; 39 40 int n,m,f,k; 41 char A[N][N],B[N][N]; 42 int dir[8][2]={{-1,0},{-1,1},{-1,-1},{0,1},{0,-1},{1,0},{1,1},{1,-1}}; 43 struct point 44 { 45 int x,y,t; 46 bool operator < (const point &a) const 47 { 48 return t<a.t; 49 } 50 }p[N*N]; 51 52 void solve() 53 { 54 for(int i=0;i<n;i++) 55 { 56 for(int j=0;j<m;j++) 57 { 58 B[i][j]=A[i][j]; 59 int ans=0; 60 for(int k=0;k<8;k++) 61 { 62 int x=i+dir[k][0]; 63 int y=j+dir[k][1]; 64 if(x<0||x>=n||y<0||y>=m) continue; 65 if(A[x][y]=='1') ans++; 66 } 67 if(A[i][j]=='1') 68 { 69 if(ans<2) B[i][j]='0'; 70 else if(ans>3) B[i][j]='0'; 71 else B[i][j]='1'; 72 } 73 else if(A[i][j]=='0') 74 { 75 if(ans==3) B[i][j]='1'; 76 } 77 } 78 } 79 for(int i=0;i<n;i++) 80 for(int j=0;j<m;j++) 81 A[i][j]=B[i][j]; 82 } 83 int main() 84 { 85 //Read(); 86 //Write() 87 int q; 88 scanf("%d",&q); 89 while(q--) 90 { 91 scanf("%d%d%d%d",&n,&m,&f,&k); 92 getchar(); 93 for(int i=0;i<n;i++) scanf("%s",A[i]); 94 for(int i=0;i<k;i++) 95 { 96 scanf("%d%d%d",&p[i].t,&p[i].x,&p[i].y); 97 p[i].x--; 98 p[i].y--; 99 } 100 sort(p,p+k); 101 for(int i=1,j=0;i<=f;i++) 102 { 103 solve(); 104 while(p[j].t==i) 105 { 106 A[p[j].x][p[j].y]='X'; 107 j++; 108 } 109 } 110 for(int i=0;i<n;i++) 111 printf("%s\n",A[i]); 112 } 113 return 0; 114 }