1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| // // main.cpp // hdu 4527 // // Created by miaoyou.gmy on 15/8/30. // Copyright (c) 2015年 miaoyou.gmy. All rights reserved. //
#include <iostream> #include <string.h> #include <queue> using namespace std;
struct node{ int x,y,d; node(int _x = 0,int _y = 0,int _d = 0):x(_x),y(_y),d(_d){} };
const int N(6); int maze[N][N]; queue<node> Q; const int dir[4][2] = { {0,1},{1,0},{-1,0},{0,-1} };
bool judge(const int x,const int y){ return (x>-1&&x<N&&y>-1&&y<N); }
void output(){ for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ if(j == 0) printf("%d",maze[i][j]); else printf(" %d",maze[i][j]); } printf("\n"); } printf("\n"); }
void deal(const int x,const int y){ maze[x][y] = 0; for(int i=0;i<4;i++){ int xx = x+dir[i][0]; int yy = y+dir[i][1]; if(judge(xx, yy)){ Q.push(node(xx,yy,i)); } } }
void found(){ for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ if(maze[i][j] > 4) deal(i, j); } } }
void bfs(){ while (!Q.empty()) { size_t size = Q.size(); while(size--){ node now = Q.front(); Q.pop(); if(maze[now.x][now.y] > 0) maze[now.x][now.y]+=1; else{ int afterx = now.x+dir[now.d][0]; int aftery = now.y+dir[now.d][1]; if(judge(afterx, aftery)){ Q.push(node(afterx,aftery,now.d)); } } } found(); } }
int main(int argc, const char * argv[]) { // freopen("in.txt", "r", stdin); int a,m,x,y; while(~scanf("%d",&a)){ maze[0][0] = a; for(int i=1;i<N;i++){ scanf("%d",&maze[0][i]); } for(int i=1;i<N;i++){ for(int j=0;j<N;j++){ scanf("%d",&maze[i][j]); } } scanf("%d",&m); while(m--){ scanf("%d%d",&x,&y); --x,--y; if(maze[x][y] < 4) maze[x][y]+=1; else{ deal(x,y); bfs(); } } output(); } return 0; }
|