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 |
Tags
- 포도주시식
- 동적계획법
- content script
- discord.js
- 2156
- 갓생
- popup
- react
- 디스코드 봇
- 백준
- supabase
- background script
- webpack
- X
- Message Passing
- C언어로 쉽게 풀어쓴 자료구조
- 백준 7579
- 공부시간측정어플
- 자료구조
- Chrome Extension
- nodejs
- 프로그래머스 #정수삼각형 #동적계획법
- 캠스터디
- 백준 #7568번 #파이썬 #동적계획법
- 파이썬
- 크롬 익스텐션
- TypeScript
- 크롬 확장자
Archives
- Today
- Total
히치키치
[백준] 2630번 : 색종이 만들기 - Python(파이썬) 본문
문제
https://www.acmicpc.net/problem/2630
2630번: 색종이 만들기
첫째 줄에는 전체 종이의 한 변의 길이 N이 주어져 있다. N은 2, 4, 8, 16, 32, 64, 128 중 하나이다. 색종이의 각 가로줄의 정사각형칸들의 색이 윗줄부터 차례로 둘째 줄부터 마지막 줄까지 주어진다.
www.acmicpc.net
아이디어
1. 재귀 시점
색깔이 다르면 4등분으로 나눔
2. 종료 시점
4개로 나눈 것에 대한 탐색 함수 각각 실행 완료 후 종료
3. 결과 처리
조각을 다 돌고 같지 않은 색깔이 없는 경우 해당 조각의 색깔을 res 배열에 저장
res 배열 내 색깔별 갯수를 출력해 결과냄
전체 코드
#https://www.acmicpc.net/problem/2630
import sys
input=sys.stdin.readline
N=int(input())
arr=[list(map(int, input().split())) for _ in range(N)]
#print(N,arr)
res=[]
def split(n,x,y):
color=arr[x][y]
#print(color)
for i in range(x,x+n):
for j in range(y,y+n):
if arr[i][j]!=color:
split(n//2,x,y)
split(n//2,x,y+n//2)
split(n//2,x+n//2,y)
split(n//2,x+n//2,y+n//2)
return
if color==0:
res.append(0)
else:
res.append(1)
split(N,0,0)
print(res.count(0))
print(res.count(1))
Comments