ZOJ 3804 YY's Minions(简单模拟)
来源:互联网 发布:java数组的作用 编辑:程序博客网 时间:2024/06/09 18:56
Despite YY's so much homework, she would like to take some time to play with her minions first.
YY lines her minions up to an N*M matrix. Every minion has two statuses: awake or asleep. We use 0(the digit) to represent that it is asleep, and 1 for awake. Also, we define the minions who are around a minion closest in one of the eight directions its neighbors. And every minute every minion will change its status by the following specific rules:
Also, some minions will get bored and leave this silly game. We use 'X's to describe them. We suppose that a minion would leave after T minutes. It will leave at the end of the Tthminute. Its status is considered during the change at the beginning of the Tth minute, and should be ignored after that. Of course, one minion will not leave twice!
YY is a girl full of curiosity and wants to know every minion's status after F minutes. But you know she is weak and lazy! Please help this cute girl to solve this problem :)
Input
There are multiple test cases.
The first line contains the number of test cases Q. 1<=Q<=100.
For each case, there are several lines:
The first line contains four integers N, M, F, K. K means the number of leaving messages. 1<=N, M<=50, 1<=F<=1000, 1<=K<=N*M.
Next N lines are the matrix which shows the initial status of each minion. Each line contains M chars. We guarantee that 'X' wouldn't appear in initial status matrix.
And next K lines are the leaving messages. Each line contains three integers Ti, Xi, Yi, They mean the minion who is located in (Xi, Yi) will leave the game at the end of the Tith minutes. 1<=Ti<= F, 1<=Xi<=N, 1<=Yi<=M.
Output
For each case, output N lines as a matrix which shows the status of each minion after F minutes.
Sample Input
23 3 2 11011100011 2 25 5 6 310111010000000001100100002 3 32 4 15 1 5
Sample Output
0101X00100000X1100000X00X000000000
Hint
For case 1:T=0, the game starts101110001---------------at the beginning of T=1, a change took place100101010---------------at the end of T=1 (the minion in (2,2) left)1001X1010---------------at the beginning of T=2, a change took place0101X0010---------------at the end of T=2 (nothing changed for no minion left at T=2)0101X0010
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 1010;char A[N][N], B[N][N];struct node { int t, x, y; bool operator < (const node &p) const{ return t < p.t; }} leave[N];int n, m, k, f;int dir[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};void solve() { for(int x = 0; x < n; x++) { for(int y = 0; y < m; y++) { int awake = 0; for(int i = 0; i < 8; i++) { int nx = x + dir[i][0]; int ny = y + dir[i][1]; if(nx < 0 || nx >= n || ny < 0 || ny >= m) continue; if(A[nx][ny] == '1') awake++; } B[x][y] = A[x][y]; if(A[x][y] == '1') { if(awake < 2) B[x][y] = '0'; else if(awake > 3) B[x][y] = '0'; else B[x][y] = '1'; } else if(A[x][y] == '0') { if(awake == 3) B[x][y] = '1'; } } } for(int x = 0; x < n; x++) { for(int y = 0; y < m; y++) A[x][y] = B[x][y]; }}int main() { int T; scanf("%d", &T); while(T--) { scanf("%d%d%d%d", &n, &m, &f, &k); for(int i = 0; i < n; i++) scanf("%s", A[i]); for(int i = 0; i < k; i++) { scanf("%d%d%d", &leave[i].t, &leave[i].x, &leave[i].y); --leave[i].x; --leave[i].y; } sort(leave, leave + k); for(int i = 1, j = 0; i <= f; i++) { solve(); while(j < k && leave[j].t == i) { A[leave[j].x][leave[j].y] = 'X'; ++j; } } for(int i = 0; i < n; i++) printf("%s\n", A[i]); } return 0;}
- ZOJ 3804 YY's Minions(简单模拟)
- ZOJ 3804 YY's Minions(模拟)
- ZOJ-3804---YY's Minions (模拟)
- ZOJ 3804 YY's Minions(模拟)
- ZOJ - 3804 YY's Minions(模拟)
- ZOJ 3804 YY's Minions(搜索+模拟)
- ZOJ 3804 YY's Minions
- ZOJ 3804 YY's Minions
- ZOJ 3804 YY's Minions
- YY's Minions - ZOJ 3804 搜索
- ZOJ3804:YY's Minions(模拟)
- zoj 3804 YY's Minions (ZOJ Monthly, August 2014 - G)
- 组队赛#1 解题总结 ZOJ 3803 YY's Minions (DFS搜索+模拟)
- ZOJ3804_YY's Minions 模拟
- ZOJ Fiddlesticks (简单模拟)
- Chang'an(YY's string-模拟)
- ZOJ 3829 Known Notation(模拟+YY)——The 2014 ACM-ICPC Asia Mudanjiang Regional Cont
- zoj S-Trees 1150 (二叉树模拟)
- Cisco和H3C命令对照(部分)
- C语言注释风格(函数、功能、输入、输出、返回)
- “bind failed on XXXX: Address already in usr”问题
- merge的妙用
- Solr 4.7.0 在windows7 & tomcat7.0.55 下部署及使用
- ZOJ 3804 YY's Minions(简单模拟)
- 虚函数和抽象类
- MATLAB读写mat文件
- Android 动画详解之Frame动画 (Drawable Animation)
- Delphi字符串加密解密函数
- Android中Is library配置的作用
- Visual C++2010中CMFCPropertySheet的用法
- Hibernate关系映射基础
- Timer