This repository was archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
[2023-08-18] wooyeol #114 #135
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
종이의 개수 | ||
https://www.acmicpc.net/problem/1780 | ||
|
||
풀이시간 | ||
08:30 ~ 09:30 + 13:30~14:44 (2시간 14분) | ||
N(1 <= N <= 3**7, N은 3**k 꼴) | ||
|
||
접근법 | ||
무슨 알고리즘으로 풀이 할 수 있을까? 재귀 / 분할 정복 | ||
|
||
문제에는 두 가지 조건이 주어진다. 첫 번째는 9개의 값이 같은 값이라면 그 종이는 하나 | ||
9개의 값이 다른 경우 그 종이는 각각 하나의 종이씩이다. | ||
|
||
그렇기에 범위 내의 데이터가 모두 같을 경우와 같지 않을 경우를 검사하고 같지 않다면 | ||
9개로 나눠서 다시 연산 진행 3**N 으로 주어지기에 3**(N-1)의 경우 다시 검사하여 | ||
9개로 나눠진 값이 각각 하나씩만 반환할 때까지 분할해서 정복한다. | ||
|
||
풀이 참조 : https://velog.io/@yje876/python백준분할정복-1780-종이의-개수 | ||
""" | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
|
||
N = int(input()) | ||
|
||
paper = [list(map(int, input().split())) for _ in range(N)] | ||
|
||
values: dict = {-1: 0, 0: 0, 1: 0} | ||
|
||
|
||
# 해당 범위 내의 데이터가 모두 같은 값인지 확인 | ||
def is_same_value(n: int, row: int, col: int): | ||
for i in range(row, row + n): | ||
for j in range(col, col + n): | ||
if paper[row][col] != paper[i][j]: | ||
return False | ||
return True | ||
|
||
|
||
def recursive(n: int, row: int, col: int): | ||
# 조건 1: 하나의 값으로만 이루어져 있을 경우 | ||
if not is_same_value(n, row, col): | ||
# 조건 2 : 9개의 값 확인하여 갯수 확인 | ||
n_trisection = n // 3 | ||
|
||
# 첫번째 행 | ||
recursive(n_trisection, row, col) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 친구들도 마찬가지로 직관적이어서 좋습니다! 다만 보는 관점에 따라서 해당 9개의 경우의 수를 반복문으로 작성하는 경우를 좋게 보는 분들도 계실 것 같네요. 시간 날 때 한 번 개선해보시면 좋을 것 같습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 지수님 말씀처럼 저는 이 부분을 반복문으로 구현해서 풀었는데 반복문으로 써보시면 코드가 좀 더 간결해보일 수 있을 것 같아요! |
||
recursive(n_trisection, row, col + n_trisection) | ||
recursive(n_trisection, row, col + (2 * n_trisection)) | ||
|
||
# 두번째 행 | ||
recursive(n_trisection, row + n_trisection, col) | ||
recursive(n_trisection, row + n_trisection, col + n_trisection) | ||
recursive(n_trisection, row + n_trisection, col + (2 * n_trisection)) | ||
|
||
# 세번째 행 | ||
recursive(n_trisection, row + (2 * n_trisection), col) | ||
recursive(n_trisection, row + (2 * n_trisection), col + n_trisection) | ||
recursive(n_trisection, row + (2 * n_trisection), col + (2 * n_trisection)) | ||
return | ||
else: | ||
# 결과에 따른 값 카운트 | ||
values[paper[row][col]] += 1 | ||
|
||
|
||
recursive(N, 0, 0) | ||
|
||
for value in values.values(): | ||
print(value) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 함수 덕에 훨씬 직관적이네요!