-
[백준] 17822 - 원판 돌리기Algorithm 문제 2019. 12. 2. 15:56
https://www.acmicpc.net/problem/17822
회전 시의 인덱스 변화를 잘 신경쓴다면 어렵지 않은 구현 문제..
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192#include <cstdio>using namespace std;int n, m, t;int arr[52][52], rot[52], check[52][52];int dv[2] = {1, -1};inline int idx(int i){int t = ((i % m) + m) % m;if(t == 0) return m;else return t;}void near(){for(int i=1; i<=n; i++){for(int j=1; j<=m; j++){check[i][j] = 0;}}for(int i=1; i<=n; i++){// 좌우 근접for(int j=1; j<m; j++){if(arr[i][j] == arr[i][j+1]){check[i][j] = check[i][j+1] = 1;}}if(arr[i][1] == arr[i][m]) check[i][1] = check[i][m] = 1;// 상하 근접for(int j=1; j<=m; j++){if(arr[i][j] == arr[i+1][idx(j + rot[i] - rot[i+1])]){check[i][j] = check[i+1][idx(j + rot[i] - rot[i+1])] = 1;}}}bool change = false;for(int i=1; i<=n; i++){for(int j=1; j<=m; j++){if(check[i][j] == 1){if(arr[i][j] != 0) change = true;arr[i][j] = 0;}}}if(!change){int cnt = 0, s = 0;for(int i=1; i<=n; i++){for(int j=1; j<=m; j++){if(arr[i][j] != 0){cnt++;s += arr[i][j];}}}double aver = (double)s / cnt;for(int i=1; i<=n; i++){for(int j=1; j<=m; j++){if(arr[i][j] != 0 && arr[i][j] > aver) arr[i][j]--;else if(arr[i][j] != 0 && arr[i][j] < aver) arr[i][j]++;}}}}int main(){scanf("%d %d %d", &n, &m, &t);for(int i=1; i<=n; i++){for(int j=1; j<=m; j++){scanf("%d", &arr[i][j]);}}for(int v=0; v<t; v++){int x, d, k;scanf("%d %d %d", &x, &d, &k);for(int i=x; i<=n; i+=x){rot[i] += dv[d] * k;}near();}int re = 0;for(int i=1; i<=n; i++){for(int j=1; j<=m; j++){re += arr[i][j];}}printf("%d", re);return 0;}cs 'Algorithm 문제' 카테고리의 다른 글
[백준] 14268 - 내리 갈굼 2 (0) 2019.12.09 [백준] 14267 - 내리갈굼 (0) 2019.12.09 [백준] 2357 - 최솟값과 최댓값 (0) 2019.11.30 [백준] 12766 - 지사 배정 (0) 2019.11.26 [백준] 17142 - 연구소 3 (0) 2019.07.28