Deep Learning study
백준 17144문제 본문
반응형
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a ; i<b ; i++)
#define FOR_(i,a,b) for(int i=a ; i>b ; i--)
int x[4] = {0,0,1,-1};
int y[4] = {1,-1,0,0};
int R,C,T,r1,r2,r[2],m[51][51],v[51][51];
bool check(int x, int y){
return (x<R && x>=0 && y<C && y>=0);
}
void proliferation(int a, int b){
int cnt=0,prol = m[a][b]/5;
FOR(i,0,4){
int nx = a + x[i], ny = b + y[i];
if(check(nx,ny) && m[nx][ny]!=-1) cnt++;
}
m[a][b] = m[a][b] - prol * cnt;
v[a][b] = prol;
}
void update(){
FOR(i,0,R) FOR(j,0,C){
FOR(k,0,4){
int nx = i + x[k], ny = j+y[k];
if(check(nx,ny) && m[nx][ny]!=-1) m[nx][ny] += v[i][j];
}
}
}
void clean(){
FOR_(i,r1-1,0) m[i][0] = m[i-1][0];
FOR(i,0,C-1) m[0][i] = m[0][i+1];
FOR(i,0,r1) m[i][C-1] = m[i+1][C-1];
FOR_(i,C-1,1) m[r1][i] = m[r1][i-1];
m[r1][1] = 0;
FOR(i,r2+1,R-1) m[i][0] = m[i+1][0];
FOR(i,0,C-1) m[R-1][i] = m[R-1][i+1];
FOR_(i,R-1,r2) m[i][C-1] = m[i-1][C-1];
FOR_(i,C-1,1) m[r2][i] = m[r2][i-1];
m[r2][1] = 0;
}
int main(){
ios_base::sync_with_stdio(false);
cin >> R >> C >> T;
int idx = 0;
FOR(i,0,R) FOR(j,0,C){
int inp;
cin >> inp;
if(inp && inp != -1) v[i][j] = 1;
if(inp == -1) r[idx++] = i;
m[i][j] = inp;
}
r1 = r[0], r2 = r[1];
FOR(l,0,T){
FOR(i,0,R) FOR(j,0,C) proliferation(i,j);
update();
clean();
FOR(i,0,R) FOR(j,0,C) v[i][j] = 0;
}
int ans = 2;
FOR(i,0,R) FOR(j,0,C) ans += m[i][j];
cout << ans << endl;
return 0;
}
백준 미세먼지 안녕! 문제 풀이입니다.!
반응형
'백준 문제 코드' 카테고리의 다른 글
백준 14888문제 (0) | 2019.12.31 |
---|---|
백준 14503문제 (0) | 2019.12.18 |
백준 14889문제 (0) | 2019.12.17 |
백준 3190문제 (0) | 2019.12.16 |
백준 14500문제 (0) | 2019.12.16 |
Comments