코테 준비/분할정복
-
[백준] 1074. Z (다시 풀기)코테 준비/분할정복 2023. 1. 15. 02:45
import sys n,r,c=map(int,sys.stdin.readline().split()) def Z(n,r,c,count): if n==1: if r==0 and c==0: print(count) if r==0 and c==1: print(count+1) if r==1 and c==0: print(count+2) if r==1 and c==1: print(count+3) else: #왼쪽 위는 숫자를 늘릴 필요 없음 if r=(2**n)//2: #오른쪽 위 count+=((2**n)//2)**2 c-=((2**n)//2) elif r>=(2**n)//2 and c=(2**n)//2 and c>=(2**n)//2: #오른쪽 아래 count+=((2**n)//2)**2*3 r-=((2**n)//2)..
-
[백준] 1780. 종이의 개수 / 파이썬(Python)코테 준비/분할정복 2023. 1. 9. 23:16
n=int(input()) graph=[[0]*n for _ in range(n)] for i in range(n): graph[i]=list(map(int,input().split())) minus_one=0 zero=0 one=0 def paper_num(n,div_graph): global minus_one global zero global one count=0 zero_count=0 for i in range(n): count+=sum(div_graph[i]) zero_count+=div_graph[i].count(0) # 0의 개수 count if count==n**2: # 전부다 1일 때 one+=1 elif count==-(n**2): # 전부다 -1일 때 minus_one+=1 elif z..
-
분할정복 문제를 푸는 방법코테 준비/분할정복 2023. 1. 9. 04:30
https://moz1e.tistory.com/85 [백준BOJ] 단계별로 문제풀기 - 분할 정복 정답 및 후기(파이썬, python) 백준 알고리즘에서 제공되는 문제들 중 단계별로 문제 풀기 - 분할 정복 1번~10번을 파이썬으로 풀어보았다. 분할정복 10문제 모두 깃허브에 올려놓았다. www.acmicpc.net/step/20 분할 정복 단계 히스토 moz1e.tistory.com 분할정복의 핵심은 큰 문제를 작은 문제 여러개로 나누어서 해결하는 것이기 때문에 대부분 재귀함수를 사용한다. ex. 그래프 분할 정복 문제 def divandconquer(입력값 n, 그래프 graph): if (간단하게 해결되는 경우): return ~ else: 그래프 분할 경우1 divandconquer(n//2,gr..
-
[백준] 1992. 쿼드트리코테 준비/분할정복 2023. 1. 9. 04:22
색종이 문제랑 똑같은데 출력 형식만 다름 n=int(input()) graph=[[0]*n for _ in range(n)] for i in range(n): graph[i]=list(map(int,input())) result=[] def quad_tree(n,div_graph): global result one_num=0 for i in range(n): one_num+=sum(div_graph[i]) if one_num==0: result.append(0) elif one_num==n**2: result.append(1) else: result.append('(') divide=[div_graph[i][:n//2] for i in range(n//2)] #사각형 네개로 나눴을 때 왼쪽 위 quad_..
-
[백준] 2630. 색종이 만들기코테 준비/분할정복 2023. 1. 9. 04:22
색종이를 계속 4등분해서 왼쪽 위 / 왼쪽 아래 / 오른쪽 위 / 오른쪽 아래로 나눠서 생각해야함 n=int(input()) graph=[] white=0 blue=0 for i in range(n): graph.append(list(map(int,input().split()))) def divideconquer(n,div_graph): global white global blue one_num=0 for i in range(n): one_num+=sum(div_graph[i]) if one_num==0: #전부다 0이면 white+=1 elif one_num==n**2: #전부다 1이면 blue+=1 else: divide=[div_graph[i][:n//2] for i in range(n//2)] #..