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
- 백준
- 백준 7579
- 동적계획법
- 크롬 익스텐션
- 파이썬
- background script
- 백준 #7568번 #파이썬 #동적계획법
- nodejs
- Message Passing
- 디스코드 봇
- supabase
- 갓생
- 크롬 확장자
- Chrome Extension
- TypeScript
- content script
- 포도주시식
- 2156
- 자료구조
- 공부시간측정어플
- 캠스터디
- C언어로 쉽게 풀어쓴 자료구조
- react
- webpack
- X
- 프로그래머스 #정수삼각형 #동적계획법
- discord.js
- popup
Archives
- Today
- Total
히치키치
[백준] 2630번 : 색종이 만들기 - Python(파이썬) 본문
풀이
- 분할 정복
- 적절한 인덱싱을 통해 4분할 구현
- 모든 칸이 같은 색으로 사분할이 진행되지 않으면 갯수 추가
코드
import sys
input=sys.stdin.readline
def cut(n,x,y):
global b,w
color=array[x][y]
for i in range(x,x+n):
for j in range(y,y+n):
if color!=array[i][j]:
cut(n//2,x,y)
cut(n//2,x,y+n//2)
cut(n//2,x+n//2,y)
cut(n//2,x+n//2,y+n//2)
return
if color==0:
w+=1
return
else:
b+=1
return
N=int(input())
array=[list(map(int,input().split())) for _ in range(N)]
w=0
b=0
cut(N,0,0)
print(w)
print(b)
헷갈렸던 점
#(1)blue와 white 갯수를 저장하는 변수 -> global 선언
def cut(n,x,y):
global b,w
#사분할 분할 탐색 - 적절한 인덱싱으로 재귀 구현
for i in range(x,x+n):
for j in range(y,y+n):
if color!=array[i][j]: #한개라도 배열안에서 색깔이 다르면 사분할 진행
cut(n//2,x,y)
cut(n//2,x,y+n//2)
cut(n//2,x+n//2,y)
cut(n//2,x+n//2,y+n//2)
'알고리즘 스터디' 카테고리의 다른 글
[백준] 1939번 : 중량제한 - Python(파이썬) (0) | 2021.03.22 |
---|---|
[백준] 1339번 : 단어수학 - Python(파이썬) (0) | 2021.03.22 |
[백준] 17829번 : 222-풀링 - Python(파이썬) (0) | 2021.03.22 |
[백준] 2293번 : 동전 1 - Python(파이썬) (0) | 2021.03.04 |
[프로그래머스] 정수 삼각형 - Python(파이썬) (0) | 2021.03.03 |
Comments