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 |
Tags
- 엘라스틱서치
- 이젠 골드구현도 어렵네..
- java
- 백준
- dp
- 알고리즘
- 재귀함수
- GatherTown
- 시뮬레이션
- 다이나믹프로그래밍
- 네트워크플로우
- DFS
- spring
- COSPROJAVA1급
- 구현
- BFS
- 취득후기
- 백준코딩테스트
- 세그먼트트리
- 우선순위큐
- YBMCOS
- 자바PS
- QUICKSTARTGUIDE
- 게더타운시작
- 완전탐색
- deque
- 01BFS
- COSPRO
- 다익스트라
- PS
Archives
- Today
- Total
공부공간
BOJ-2630 ) 색종이 만들기 본문
https://www.acmicpc.net/problem/2630
현재좌표와 한변의 길이를 재귀함수의 인자값으로 받는다, 한변의 길이가 N이라면 N>>1씩 쪼개서
현재범위가 같은 색상인지 판단한다. 같은색상이라면, 탐색을 멈추고 다른색상이라면 4등분하여 탐색을 진행한다.
package algorithm_2022;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ_2630 {
public static int map[][],blue,white;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
map=new int[N][N];
for(int i=0;i<N;i++) {
st = new StringTokenizer(br.readLine());
for(int j=0;j<N;j++) {
map[i][j] = Integer.parseInt(st.nextToken());
}
}
recursion(0,0,N);
System.out.println(white+"\n"+blue);
}
private static void recursion(int y,int x, int n) {
boolean isAllSame = true;
int init = map[y][x];
for(int i=y;i<y+n;i++) {
for(int j=x;j<x+n;j++) {
if(map[i][j]!=init) {
isAllSame=false;
}
}
if(!isAllSame) break;
}
if(isAllSame) {
init = (init==1) ? blue++ : white++;
return;
} else {
recursion(y,x,n>>1);
recursion(y,x+(n>>1),n>>1);
recursion(y+(n>>1),x,n>>1);
recursion(y+(n>>1),x+(n>>1),n>>1);
return;
}
}
}
'알고리즘' 카테고리의 다른 글
BOJ-1074 ) Z (0) | 2022.02.13 |
---|---|
BOJ-11723 ) 집합 (0) | 2022.02.06 |
BOJ-1021 ) 회전하는 큐 (1) | 2022.02.03 |
Comments