很水的一个模拟。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
struct Node
{
int t, x, y;
Node(int t, int x, int y):t(t), x(x), y(y) {}
bool operator < (const Node a)const
{
return t>a.t;
}
};
priority_queue<Node> q;
int m, n, f;
char g[55][55], tmp[55][55];
int dx[]= {-1, -1, -1, 1, 1, 1, 0, 0};
int dy[]= {-1, 1, 0, 1, 0, -1, 1, -1};
int inside(int x, int y)
{
return x>=0 && x<m && y>=0 && y<n;
}
int cnt(int x, int y)
{
int ans=0;
for(int i=0; i<8; i++)
{
int nx=dx[i]+x, ny=dy[i]+y;
if(inside(nx, ny) && g[nx][ny]=='1')
ans++;
}
return ans;
}
void solve(int t)
{
for(int i=0; i<m; i++)
for(int j=0; j<n; j++)
{
int cc=cnt(i, j);
if(g[i][j]=='X')
tmp[i][j]='X';
else if(g[i][j]=='1' && (cc==2 || cc==3))
tmp[i][j]='1';
else if(g[i][j]=='0' && cc==3)
tmp[i][j]='1';
else tmp[i][j]='0';
}
while(!q.empty() && t==q.top().t)
{
Node node=q.top();
q.pop();
tmp[node.x][node.y]='X';
}
memcpy(g, tmp, sizeof(g));
}
int main()
{
int T, tt;
scanf("%d", &T);
while(T--)
{
memset(tmp, 0, sizeof(tmp));
scanf("%d%d%d%d", &m, &n, &f, &tt);
for(int i=0; i<m; i++)
scanf("%s", g[i]);
while(!q.empty())
q.pop();
while(tt--)
{
int t, x, y;
scanf("%d%d%d", &t, &x, &y);
q.push(Node(t, x-1, y-1));
}
for(int i=1; i<=f; i++)
solve(i);
for(int i=0; i<m; i++)
puts(g[i]);
}
return 0;
}