일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Hasing
- colorSyntax
- 10162
- BOJ
- 구간 합 구하기 4
- 정수 삼각형
- javascript
- 이분탐색
- 옵셔널 체이닝 연산자
- 주식 가격
- 4796
- 다이내믹 프로그래밍
- 없는 숫자 더하기
- C++
- 깊이 우선 탐색
- codeSyntaxHighlight
- 숫자 문자열과 영단어
- 소수 체크
- Git Convention
- 프로그래머스
- js
- 18111
- react
- 5525
- n^2 배열 자르기
- 브루트포스 알고리즘
- mermaid js
- 위클리 챌린지
- 1620
- 2018 KAKAO BLIND RECRUITMENT
Archives
- Today
- Total
개발하는 kim-hasa
[c++][BOJ][2630] 색종이 만들기 본문
https://www.acmicpc.net/problem/2630
2630번: 색종이 만들기
첫째 줄에는 전체 종이의 한 변의 길이 N이 주어져 있다. N은 2, 4, 8, 16, 32, 64, 128 중 하나이다. 색종이의 각 가로줄의 정사각형칸들의 색이 윗줄부터 차례로 둘째 줄부터 마지막 줄까지 주어진다.
www.acmicpc.net
색종이에 같은 숫자가 있는 사각형끼리 모아서 잘라내는 문제입니다.
가장 먼저 , 색종이가 1로만 이루어져 있는지 0으로만 이루어져 있는지 체크합니다.
섞여있다면 , 4등분 하고 다시 1과 0으로만 이루어져 있는지 체크합니다.
섞이지 않았다면 , 1 또는 0으로만 이루어져 있으므로 count를 체크합니다.
마지막에 1칸짜리만 남았다면 , 그 칸이 1인지 0인지 확인해서 카운트를 증가시킵니다.
#include <iostream>
using namespace std;
int arr[128][128] = {0};
int count1 = 0;
int count0 = 0;
void find(int xleft , int xright, int yleft , int yright, int index ){
if(index == 1){
if(arr[xleft][yleft] == 1){
count1++;
}
else {
count0++;
}
return;
}
bool find1 = false;
bool find2 = false;
for(int i=xleft; i<=xright; i++){
for(int j=yleft; j<=yright; j++){
if(arr[i][j] == 1)
find1 = true;
else if(arr[i][j] == 0)
find2 = true;
if(find1 == find2)
break;
}
}
if(find1 == find2){
index /= 2;
find(xleft, xleft+index-1, yleft , yleft+index-1, index);
find(xleft+index, xright, yleft, yleft+index-1, index);
find(xleft, xleft+index-1, yleft+index, yright, index);
find(xleft+index, xright, yleft+index, yright , index);
}
else if(find1 == true){
count1++;
}
else {
count0++;
}
}
int main(){
int n;
cin >> n;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
cin >> arr[i][j];
}
}
find(0 , n-1 , 0 , n-1, n);
cout << count0 << '\n';
cout << count1;
}
'Algorithm > BOJ' 카테고리의 다른 글
[c++][BOJ][1992] 쿼드트리 (0) | 2022.03.02 |
---|---|
[c++][BOJ][1780] 종이의 개수 (0) | 2022.03.02 |
[c++][BOJ][1620] 나는야 포켓몬 마스터 이다솜 (0) | 2022.03.01 |
[c++][BOJ][5525] IOIOI (0) | 2022.03.01 |
[c++][BOJ][1541] 잃어버린 괄호 (0) | 2022.03.01 |