-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path12187-Brothers.cpp
55 lines (53 loc) · 1.34 KB
/
12187-Brothers.cpp
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
#include <iostream>
#include <fstream>
#include <sstream>
#include <cmath>
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
using namespace std;
void battle(vector<vector<int> >& g,int n){
vector<vector<int> > next(g);
int rowSize = g.size();
int colSize = g[0].size();
for(int i=0;i<rowSize;i++){
for(int j=0;j<colSize;j++){
int opp = (g[i][j]+1) % n;
if(i!=0 && g[i-1][j] == opp)
next[i-1][j] = g[i][j];
if(i+1!=rowSize && g[i+1][j] == opp)
next[i+1][j] = g[i][j];
if(j!=0 && g[i][j-1] == opp)
next[i][j-1] = g[i][j];
if(j+1!=colSize && g[i][j+1] == opp)
next[i][j+1] = g[i][j];
}
}
g = next;
}
int main(){
int n,r,c,k;
while(scanf("%d %d %d %d",&n,&r,&c,&k),n){
vector<vector<int> > g(r,vector<int>(c));
int v;
for(int i=0;i<r;i++) for(int j=0;j<c;j++){
cin >> v;
g[i][j] = v;
}
while(k--){
battle(g,n);
}
for(int i=0;i<r;i++) {
for(int j=0;j<c;j++){
cout << g[i][j] << (j+1 == c ? "\n" : " ");
}
}
}
}