Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 문자열
- 문제해결
- 시뮬레이션
- SQL
- 자바
- oracle
- 운동기록
- 프로그래머스
- MySQL
- 코테
- COS PRO
- priorityqueue
- binary search
- db
- 문제풀이
- DP
- Java
- SWEA
- 건강
- 백준
- BOJ
- 알고리즘
- math
- 이분탐색
- dfs
- 코딩테스트
- BFS
- 러닝일지
- 투포인터
- greedy
Archives
- Today
- Total
슈콩
[BOJ] 17822 원판돌리기 본문
[문제]





[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int m;
static int[][] map;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
int t = Integer.parseInt(st.nextToken());
map = new int[n+1][m];
for(int i=1;i<=n;i++) {
st = new StringTokenizer(br.readLine());
for(int j=0;j<m;j++) {
map[i][j] = Integer.parseInt(st.nextToken());
}
}
for(int tc=0;tc<t;tc++) {
st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
for(int i=x;i<=n;i+=x) rotate(i,d,k);
boolean check = false;
double sum = 0;
int cnt = 0;
boolean[][] visit = new boolean[n+1][m];
for(int i=1;i<=n;i++) {
for(int j=0;j<m;j++) {
if(map[i][j]==0) continue;
int curr = map[i][j];
if(curr==map[i][(j+1)%m])
visit[i][j] = visit[i][(j+1)%m] = true;
if(curr==map[i][(j+m-1)%m])
visit[i][j] = visit[i][(j+m-1)%m] = true;
if(i>1 && curr==map[i-1][j])
visit[i][j] = visit[i-1][j] = true;
if(i<n && curr==map[i+1][j])
visit[i][j] = visit[i+1][j] = true;
sum += curr;
cnt++;
}
}
for(int i=1;i<=n;i++) {
for(int j=0;j<m;j++) {
if(visit[i][j]) {
map[i][j] = 0;
check = true;
}
}
}
if(!check) {
sum /= cnt;
for(int i=1;i<=n;i++) {
for(int j=0;j<m;j++) {
if(map[i][j]==0) continue;
if(map[i][j]>sum) map[i][j]--;
else if(map[i][j]<sum) map[i][j]++;
}
}
}
}
int result = 0;
for(int i=1;i<=n;i++) {
for(int j=0;j<m;j++) {
result += map[i][j];
}
}
System.out.println(result);
}
private static void rotate(int x,int d,int k) {
int[] temp = map[x].clone();
for (int j=0;j<m;j++) {
if(d==0) map[x][j] = temp[(j+m-k) % m];
else map[x][j] = temp[(j+k) % m];
}
}
}
회전 후, 주변 값 확인
'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 19236 청소년 상어 (0) | 2025.12.17 |
|---|---|
| [BOJ] 17825 주사위 윷놀이 (5) | 2025.12.16 |
| [BOJ] 17837 새로운 게임 2 (0) | 2025.12.09 |
| [BOJ] 17779 게리멘더링 2 (0) | 2025.12.08 |
| [BOJ] 17142 연구소3 (3) | 2025.12.07 |