Skip to content

Commit

Permalink
Merge pull request #91 from AlgoLeadMe/22-janghw0126
Browse files Browse the repository at this point in the history
22-janghw0126
  • Loading branch information
janghw0126 authored Mar 14, 2024
2 parents 69ab99c + 881588b commit ece9e6d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 19 deletions.
39 changes: 20 additions & 19 deletions janghw0126/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@

| 차시 | 날짜 | 문제유형 | 링크 | 풀이 |
|:----:|:---------:|:----:|:-----:|:----:|
| 1차시 | 2024.1.1 | Hash | <a href= "https://school.programmers.co.kr/learn/courses/30/lessons/42576">완주하지 못한 선수</a> |[#4](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/4) |
| 2차시 | 2024.1.4 | Implementation | <a href= "https://www.acmicpc.net/problem/1152">단어의 개수</a> |[#9](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/9) |
| 3차시 | 2024.1.7 | Implementation | <a href= "https://www.acmicpc.net/problem/1157">단어 공부</a> |[#13](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/13) |
| 4차시 | 2024.1.10 | Implementation | <a href= "https://www.acmicpc.net/problem/2869">달팽이는 올라가고 싶다</a> |[#20](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/20) |
| 5차시 | 2024.1.13 | Mathematics | <a href= "https://www.acmicpc.net/problem/2581">소수</a> |[#24](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/24) |
| 6차시 | 2024.1.16 | Stack | <a href= "https://www.acmicpc.net/problem/28278">스택 2</a> |[#26](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/26) |
| 7차시 | 2024.1.19 | Stack | <a href= "https://www.acmicpc.net/problem/9012">괄호</a> |[#30](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/30) |
| 8차시 | 2024.1.23 | Stack | <a href= "https://www.acmicpc.net/problem/1874">스택 수열</a> |[#36](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/36) |
| 9차시 | 2024.1.25 | Stack | <a href= "https://www.acmicpc.net/problem/4949">균형잡힌 세상</a> |[#40](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/40) |
| 10차시 | 2024.1.28 | Queue | <a href= "https://www.acmicpc.net/problem/10845">큐</a> |[#42](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/42) |
| 11차시 | 2024.2.1 | Queue | <a href= "https://www.acmicpc.net/problem/1966">프린터 큐</a> |[#48](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/48) |
| 1차시 | 2024.1.1 | 해시 | <a href= "https://school.programmers.co.kr/learn/courses/30/lessons/42576">완주하지 못한 선수</a> |[#4](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/4) |
| 2차시 | 2024.1.4 | 구현 | <a href= "https://www.acmicpc.net/problem/1152">단어의 개수</a> |[#9](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/9) |
| 3차시 | 2024.1.7 | 구현 | <a href= "https://www.acmicpc.net/problem/1157">단어 공부</a> |[#13](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/13) |
| 4차시 | 2024.1.10 | 구현 | <a href= "https://www.acmicpc.net/problem/2869">달팽이는 올라가고 싶다</a> |[#20](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/20) |
| 5차시 | 2024.1.13 | 수학 | <a href= "https://www.acmicpc.net/problem/2581">소수</a> |[#24](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/24) |
| 6차시 | 2024.1.16 | 스택 | <a href= "https://www.acmicpc.net/problem/28278">스택 2</a> |[#26](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/26) |
| 7차시 | 2024.1.19 | 스택 | <a href= "https://www.acmicpc.net/problem/9012">괄호</a> |[#30](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/30) |
| 8차시 | 2024.1.23 | 스택 | <a href= "https://www.acmicpc.net/problem/1874">스택 수열</a> |[#36](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/36) |
| 9차시 | 2024.1.25 | 스택 | <a href= "https://www.acmicpc.net/problem/4949">균형잡힌 세상</a> |[#40](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/40) |
| 10차시 | 2024.1.28 | | <a href= "https://www.acmicpc.net/problem/10845">큐</a> |[#42](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/42) |
| 11차시 | 2024.2.1 | | <a href= "https://www.acmicpc.net/problem/1966">프린터 큐</a> |[#48](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/48) |
| 12차시 | 2024.2.4 | DFS | <a href= "https://www.acmicpc.net/problem/3109">빵집</a> |[#53](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/53) |
| 13차시 | 2024.2.7 | DFS | <a href= "https://www.acmicpc.net/problem/2606">바이러스</a> |[#57](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/57) |
| 14차시 | 2024.2.12 | Backtracking | <a href= "https://www.acmicpc.net/problem/15649">N과 M (1)</a> |[#61](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/61) |
| 15차시 | 2024.2.15 | Backtracking | <a href= "https://www.acmicpc.net/problem/15650">N과 M (2)</a> |[#65](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/65) |
| 16차시 | 2024.2.18 | Backtracking | <a href= "https://www.acmicpc.net/problem/15654">N과 M (5)</a> |[#66](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/66) |
| 17차시 | 2024.2.21 | Backtracking | <a href= "https://www.acmicpc.net/problem/15651">N과 M (3)</a> |[#72](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/72) |
| 18차시 | 2024.2.24 | Greedy | <a href= "https://www.acmicpc.net/problem/1541">잃어버린 괄호</a> |[#77](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/77) |
| 19차시 | 2024.2.27 | Binary Search | <a href= "https://www.acmicpc.net/problem/11663">선분 위의 점</a> |[#79](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/79) |
| 20차시 | 2024.3.2 | Binary Search | <a href= "https://www.acmicpc.net/problem/1920">수 찾기</a> |[#85](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/85) |
| 21차시 | 2024.3.5 | Number theory | <a href= "https://www.acmicpc.net/problem/17425">약수의 합</a> |[#89](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/89) |
| 14차시 | 2024.2.12 | 백트래킹 | <a href= "https://www.acmicpc.net/problem/15649">N과 M (1)</a> |[#61](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/61) |
| 15차시 | 2024.2.15 | 백트래킹 | <a href= "https://www.acmicpc.net/problem/15650">N과 M (2)</a> |[#65](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/65) |
| 16차시 | 2024.2.18 | 백트래킹 | <a href= "https://www.acmicpc.net/problem/15654">N과 M (5)</a> |[#66](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/66) |
| 17차시 | 2024.2.21 | 백트래킹 | <a href= "https://www.acmicpc.net/problem/15651">N과 M (3)</a> |[#72](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/72) |
| 18차시 | 2024.2.24 | 그리디 | <a href= "https://www.acmicpc.net/problem/1541">잃어버린 괄호</a> |[#77](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/77) |
| 19차시 | 2024.2.27 | 이진 탐색 | <a href= "https://www.acmicpc.net/problem/11663">선분 위의 점</a> |[#79](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/79) |
| 20차시 | 2024.3.2 | 이진 탐색 | <a href= "https://www.acmicpc.net/problem/1920">수 찾기</a> |[#85](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/85) |
| 21차시 | 2024.3.5 | 정수론 | <a href= "https://www.acmicpc.net/problem/17425">약수의 합</a> |[#89](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/89) |
| 22차시 | 2024.3.8 | 분할 정복 | <a href= "https://www.acmicpc.net/problem/1780">종이의 개수</a> |[#91](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/91) |
---
40 changes: 40 additions & 0 deletions janghw0126/분할 정복/Divide and Conquer_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import sys
input= sys.stdin.readline
# 재귀를 사용하기 위해 최대 깊이를 설정해준다.
sys.setrecursionlimit(1000)

# N을 입력받는다.
n=int(input())

# N개의 정수들을 행렬로 입력받는다.
matrix=[list(map(int,input().split())) for _ in range(n)]

# 종이의 갯수를 저장하는 리스트를 초기화한다.
cnt=[]

# 분할 정복을 시작한다.
def divide(x,y,n):
# 현재 구간의 색깔을 저장한다.
color=matrix[x][y]
# 현재 구간 내의 모든 정수들을 반복하면서 색깔이 같은지 확인한다.
for i in range(x,x+n):
for j in range(y,y+n):
# 색깔이 다른 경우 구간을 9개로 나누어 재귀적으로 divide 함수를 호출한다.
if color != matrix[i][j]:
# 9구간으로 나누기 위해 a와 b를 0부터 2까지 반복한다.
for a in range(3):
for b in range(3):
# 현재 구간을 9개의 작은 구간으로 분할하기 위해 divide 함수를 재귀 호출한다.
divide(x+(n//3)*a,y+(n//3)*b,n//3)
return
# 색깔에 따라서 갯수를 추가해준다.
if color==1:
cnt.append(1)
elif color==-1:
cnt.append(-1)
else:
cnt.append(0)

divide(0,0,n)
# 종이의 갯수를 출력한다.
print(cnt.count(-1),cnt.count(0),cnt.count(1),sep="\n")

0 comments on commit ece9e6d

Please sign in to comment.