/// Raihan Ruhin /// CSE, Jahangirnagar University. /// Dhaka-Bangladesh. /// id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive / spoj), 3235 (lightoj) /// mail: raihanruhin@ (yahoo / gmail / facebook) /// blog: ruhinraihan.blogspot.com #include<bits/stdc++.h> using namespace std; #define SET(a) memset(a,-1,sizeof(a)) #define CLR(a) memset(a,0,sizeof(a)) #define PI acos(-1.0) #define MOD 1000000007 #define MX 100010 int n, r, c, org[102][102], tmp[102][102]; int dx[]={0, 0, 1, -1}; int dy[]={1, -1, 0, 0}; void battle() { for(int i=0;i<r;i++) for(int j=0;j<c;j++) tmp[i][j]=org[i][j]; for(int i=0;i<r;i++) for(int j=0;j<c;j++) for(int k=0;k<4;k++) { int x = i+dx[k]; int y = j+dy[k]; if(x<0 || x>=r || y<0 || y>=c) continue; if(tmp[i][j] && tmp[x][y]+1==tmp[i][j]) { org[i][j]=tmp[x][y]; break; } if(!tmp[i][j] && tmp[x][y]==n-1) { org[i][j]=n-1; break; } } return; } int main() { ios_base::sync_with_stdio(0);cin.tie(0); int tc, kk=1, k; string s; char ch; while(cin>>n>>r>>c>>k && n) { for(int i=0;i<r;i++) for(int j=0;j<c;j++) cin>>org[i][j]; while(k--) battle(); for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { if(j) cout<<" "; cout<<org[i][j]; } cout<<"\n"; } } return 0; }
Friday, 2 October 2015
UVA - 12187 Brothers (UVALive - 4473, Regionals 2009 >> Latin America)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment