Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

38-pknujsp #154

Merged
merged 3 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions pknujsp/BRUTE_FORCE/38-μžλ¬Όμ‡ μ™€ μ—΄μ‡ .py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# μžλ¬Όμ‡ μ˜ 쀑간 뢀뢄이 λͺ¨λ‘ 1인지 확인
def is_valid(new_lock):
length = len(new_lock) // 3

for r in range(length, length * 2):
for c in range(length, length * 2):
if new_lock[r][c] != 1:
return False

return True

def solution(key, lock):
n = len(lock)
k = len(key)
new_lock = [[0] * (n * 3) for _ in range(n * 3)]

for r in range(n):
for c in range(n):
new_lock[r + n][c + n] = lock[r][c]

for _ in range(4):
rev_key = key[::-1]
key = []
for c in range(k):
row = []
for r in range(k):
row.append(rev_key[r][c])
key.append(row)

"""
μ—΄μ‡ λ₯Ό λŒλ¦¬λŠ” λ‘œμ§μ€ ν•œ μ€„λ‘œλ„ κ΅¬ν˜„κ°€λŠ₯ ν•©λ‹ˆλ‹€
key = [row for row in zip(*reversed(key))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μžλ‘λ‚˜λ¬΄ 문제보고 zip이 list끼리 indexλ₯Ό λ¬Άμ–΄μ„œ tuple둜 λ°˜ν™˜ν•˜λŠ” ν•¨μˆ˜κ΅¬λ‚˜ ν–ˆλŠ”λ° *reversed(key)둜 각 index μ›μ†Œμ— μ ‘κ·Όν•΄μ„œ tuple둜 λ¬Άμ–΄μ£Όλ©΄ νšŒμ „μ΄ λ˜λŠ”κ΅°μš” .... μ‘μš©μ΄ μ΄λ ‡κ²Œ λ˜λ„€μš”

μ½”λ“œκ°€ μ§„μ§œ μ†Œλ¦„μ΄ λ‹λ„€μš” πŸ«’πŸ‘

"""

for r in range(n * 2):
for c in range(n * 2):
# μžλ¬Όμ‡ μ— μ—΄μ‡ λ₯Ό λΌμš΄λ‹€
for i in range(k):
for j in range(k):
new_lock[r + i][c + j] += key[i][j]

# μžλ¬Όμ‡ μ— μ—΄μ‡ κ°€ λ”± λ“€μ–΄κ°”λŠ”μ§€ 확인
if is_valid(new_lock):
return True

# μžλ¬Όμ‡ μ—μ„œ μ—΄μ‡ λ₯Ό λΉΌμ„œ λ³΅κ΅¬μ‹œν‚¨λ‹€
for i in range(k):
for j in range(k):
new_lock[r + i][c + j] -= key[i][j]
return False
46 changes: 24 additions & 22 deletions pknujsp/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
## ✏️ 기둝

| μ°¨μ‹œ | λ‚ μ§œ | λ¬Έμ œμœ ν˜• | 링크 | 풀이 |
| :----: | :--------: | :-------------: | :-----------------------------------------------------------------------------------------------: | :--------------------------------------------------------: |
| 1μ°¨μ‹œ | 2023.10.07 | BRUTE_FORCE | [BOJ_1107](https://www.acmicpc.net/problem/1107) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/2) |
| 2μ°¨μ‹œ | 2023.10.09 | BRUTE_FORCE | [연속 λΆ€λΆ„ μˆ˜μ—΄ ν•©μ˜ 개수](https://school.programmers.co.kr/learn/courses/30/lessons/131701) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/5) |
| 3μ°¨μ‹œ | 2023.10.11 | SORT | [μ΅œμ†Ÿκ°’ λ§Œλ“€κΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/12941?language=python3) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/8) |
| 4μ°¨μ‹œ | 2023.10.13 | SORT | [νŠœν”Œ](https://school.programmers.co.kr/learn/courses/30/lessons/64065) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/9) |
| 5μ°¨μ‹œ | 2023.10.15 | κ΅¬ν˜„ | [κ΄„ν˜Έ λ³€ν™˜](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/13) |
| 6μ°¨μ‹œ | 2023.10.17 | 탐색 | [μΏΌλ“œμ••μΆ• ν›„ 개수 μ„ΈκΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/68936) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/16) |
| 7μ°¨μ‹œ | 2023.10.19 | 탐색 | [무인도 μ—¬ν–‰](https://school.programmers.co.kr/learn/courses/30/lessons/154540) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/20) |
| 8μ°¨μ‹œ | 2023.10.21 | 탐색 | [거리두기 ν™•μΈν•˜κΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/81302) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/22) |
| 9μ°¨μ‹œ | 2023.10.23 | 맡 | [μŠ€ν‚¬ 트리](https://school.programmers.co.kr/learn/courses/30/lessons/49993) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/25) |
| 10μ°¨μ‹œ | 2023.10.25 | κ΅¬ν˜„ | [μˆ˜μ‹ μ΅œλŒ€ν™”](https://school.programmers.co.kr/learn/courses/30/lessons/67257) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/28) |
| 11μ°¨μ‹œ | 2023.10.27 | 리슀트 | [μ˜μ–΄ λλ§μž‡κΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/12981) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/30) |
| 12μ°¨μ‹œ | 2023.10.30 | 큐 | [μ΄μ€‘μš°μ„ μˆœμœ„ν](https://school.programmers.co.kr/learn/courses/30/lessons/42628) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/36) |
| 13μ°¨μ‹œ | 2023.11.01 | DP | [λ“±κ΅£κΈΈ](https://school.programmers.co.kr/learn/courses/30/lessons/42898) | [#39](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/39) |
| 14μ°¨μ‹œ | 2023.11.03 | 맡 | [μ‹œμ†Œ 짝꿍](https://school.programmers.co.kr/learn/courses/30/lessons/152996) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/43) |
| 15μ°¨μ‹œ | 2023.11.05 | μˆ˜ν•™ | [μ˜ˆμƒ λŒ€μ§„ν‘œ](https://school.programmers.co.kr/learn/courses/30/lessons/12985) | [#47](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/47) |
| 16μ°¨μ‹œ | 2023.11.08 | μˆ˜ν•™ | [숫자 λ³€ν™˜ν•˜κΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/154538) | [#51](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/51) |
| 17μ°¨μ‹œ | 2023.11.10 | μŠ€νƒ | [짝지어 μ œκ±°ν•˜κΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/12973) | [#54](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/54) |
| 18μ°¨μ‹œ | 2023.11.13 | κ΅¬ν˜„ | [ν‚€νŒ¨λ“œ λˆ„λ₯΄κΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/67256) | [#60](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/60) |
| 19μ°¨μ‹œ | 2023.11.17 | κ΅¬ν˜„ | [μ‹€νŒ¨μœ¨](https://school.programmers.co.kr/learn/courses/30/lessons/42889) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/64) |
| μ°¨μ‹œ | λ‚ μ§œ | λ¬Έμ œμœ ν˜• | 링크 | 풀이 |
| :----: | :--------: | :-------------: | :-----------------------------------------------------------------------------------------------: | :---------------------------------------------------------: |
| 1μ°¨μ‹œ | 2023.10.07 | BRUTE_FORCE | [BOJ_1107](https://www.acmicpc.net/problem/1107) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/2) |
| 2μ°¨μ‹œ | 2023.10.09 | BRUTE_FORCE | [연속 λΆ€λΆ„ μˆ˜μ—΄ ν•©μ˜ 개수](https://school.programmers.co.kr/learn/courses/30/lessons/131701) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/5) |
| 3μ°¨μ‹œ | 2023.10.11 | SORT | [μ΅œμ†Ÿκ°’ λ§Œλ“€κΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/12941?language=python3) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/8) |
| 4μ°¨μ‹œ | 2023.10.13 | SORT | [νŠœν”Œ](https://school.programmers.co.kr/learn/courses/30/lessons/64065) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/9) |
| 5μ°¨μ‹œ | 2023.10.15 | κ΅¬ν˜„ | [κ΄„ν˜Έ λ³€ν™˜](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/13) |
| 6μ°¨μ‹œ | 2023.10.17 | 탐색 | [μΏΌλ“œμ••μΆ• ν›„ 개수 μ„ΈκΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/68936) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/16) |
| 7μ°¨μ‹œ | 2023.10.19 | 탐색 | [무인도 μ—¬ν–‰](https://school.programmers.co.kr/learn/courses/30/lessons/154540) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/20) |
| 8μ°¨μ‹œ | 2023.10.21 | 탐색 | [거리두기 ν™•μΈν•˜κΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/81302) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/22) |
| 9μ°¨μ‹œ | 2023.10.23 | 맡 | [μŠ€ν‚¬ 트리](https://school.programmers.co.kr/learn/courses/30/lessons/49993) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/25) |
| 10μ°¨μ‹œ | 2023.10.25 | κ΅¬ν˜„ | [μˆ˜μ‹ μ΅œλŒ€ν™”](https://school.programmers.co.kr/learn/courses/30/lessons/67257) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/28) |
| 11μ°¨μ‹œ | 2023.10.27 | 리슀트 | [μ˜μ–΄ λλ§μž‡κΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/12981) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/30) |
| 12μ°¨μ‹œ | 2023.10.30 | 큐 | [μ΄μ€‘μš°μ„ μˆœμœ„ν](https://school.programmers.co.kr/learn/courses/30/lessons/42628) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/36) |
| 13μ°¨μ‹œ | 2023.11.01 | DP | [λ“±κ΅£κΈΈ](https://school.programmers.co.kr/learn/courses/30/lessons/42898) | [#39](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/39) |
| 14μ°¨μ‹œ | 2023.11.03 | 맡 | [μ‹œμ†Œ 짝꿍](https://school.programmers.co.kr/learn/courses/30/lessons/152996) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/43) |
| 15μ°¨μ‹œ | 2023.11.05 | μˆ˜ν•™ | [μ˜ˆμƒ λŒ€μ§„ν‘œ](https://school.programmers.co.kr/learn/courses/30/lessons/12985) | [#47](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/47) |
| 16μ°¨μ‹œ | 2023.11.08 | μˆ˜ν•™ | [숫자 λ³€ν™˜ν•˜κΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/154538) | [#51](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/51) |
| 17μ°¨μ‹œ | 2023.11.10 | μŠ€νƒ | [짝지어 μ œκ±°ν•˜κΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/12973) | [#54](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/54) |
| 18μ°¨μ‹œ | 2023.11.13 | κ΅¬ν˜„ | [ν‚€νŒ¨λ“œ λˆ„λ₯΄κΈ°](https://school.programmers.co.kr/learn/courses/30/lessons/67256) | [#60](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/60) |
| 19μ°¨μ‹œ | 2023.11.17 | κ΅¬ν˜„ | [μ‹€νŒ¨μœ¨](https://school.programmers.co.kr/learn/courses/30/lessons/42889) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/64) |
| 20μ°¨μ‹œ | 2023.11.20 | λ¬Έμžμ—΄ | [μ˜Ήμ•Œμ΄ (2)](https://school.programmers.co.kr/learn/courses/30/lessons/133499) | [#70](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/70) |
| 21μ°¨μ‹œ | 2023.11.23 | 맡 | [μ˜μƒ](https://school.programmers.co.kr/learn/courses/30/lessons/42578) | [#73](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/73) |
| 22μ°¨μ‹œ | 2023.11.26 | 그리디 | [ꡬλͺ…λ³΄νŠΈ](https://school.programmers.co.kr/learn/courses/30/lessons/42885) | [#79](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/79) |
Expand All @@ -37,4 +37,6 @@
| 33μ°¨μ‹œ | 2024.02.06 | 큐 | [철둜](https://www.acmicpc.net/problem/13334) | [#132](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/132) |
| 34μ°¨μ‹œ | 2024.02.12 | BFS | [이뢄 κ·Έλž˜ν”„](https://www.acmicpc.net/problem/1707) | [#135](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/135) |
| 35μ°¨μ‹œ | 2024.02.18 | 그리디 | [선물할인](https://www.acmicpc.net/problem/25947) | [#137](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137) |
| 36μ°¨μ‹œ | 2024.02.21 | 이진탐색 | [νœ΄κ²Œμ†Œ μ„Έμš°κΈ°](https://www.acmicpc.net/problem/1477) | [#143](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143) |
| 36μ°¨μ‹œ | 2024.02.21 | 이진탐색 | [νœ΄κ²Œμ†Œ μ„Έμš°κΈ°](https://www.acmicpc.net/problem/1477) | [#143](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143) |
| 37μ°¨μ‹œ | 2024.03.04 | κ΅¬ν˜„ | [n+1 μΉ΄λ“œκ²Œμž„](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#149](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/149) |
| 38μ°¨μ‹œ | 2024.03.08 | BRUTE_FORCE | [μžλ¬Όμ‡ μ™€ μ—΄μ‡ ](https://school.programmers.co.kr/learn/courses/30/lessons/60059) | [#154](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/154) |
53 changes: 53 additions & 0 deletions pknujsp/κ΅¬ν˜„/37-μΉ΄λ“œκ²Œμž„.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
def solution(coin, cards):
a = set(cards[:len(cards) // 3])
b = set()
t = len(cards) + 1
r = 1

for i in range(len(cards) // 3 + 1, len(cards), 2):
c1, c2 = cards[i - 1], cards[i]
b.add(c1)
b.add(c2)

removed = False
# ν˜„μž¬ 가지고 μžˆλŠ” μΉ΄λ“œ λͺ©λ‘ 쀑 n + 1이 κ°€λŠ₯ν•œ 경우 확인
for x in list(a):
if t - x in a:
a.remove(t - x)
a.remove(x)
removed = True
break

if removed:
r += 1
continue

# μ½”μΈμœΌλ‘œ κ΅ν™˜ν•΄μ„œ 얻을 수 μžˆλŠ” μΉ΄λ“œ μ€‘μ—μ„œ n + 1이 λ˜λŠ” 경우λ₯Ό μ°Ύμ•„μ•Ό 함
# 코인이 μ—†μœΌλ―€λ‘œ μ’…λ£Œ
if not coin:
break

# `ν˜„μž¬ κ°–κ³  μžˆλŠ” μΉ΄λ“œ + 얻을 수 μžˆλŠ” μΉ΄λ“œ` = n + 1이 λ˜λŠ” 경우λ₯Ό 확인
for x in list(b):
if t - x in a:
a.remove(t - x)
b.remove(x)
removed = True
coin -= 1
break
# λ§ˆμ§€λ§‰ λ°©λ²•μœΌλ‘œ, 였직 κ΅ν™˜μœΌλ‘œ 얻을 수 μžˆλŠ” μΉ΄λ“œ λͺ©λ‘ μ€‘μ—μ„œ n + 1이 λ˜λŠ” 경우λ₯Ό 확인
if not removed and coin >= 2:
for x in list(b):
if t - x in b:
b.remove(t - x)
b.remove(x)
removed = True
coin -= 2
break

# n + 1을 μ–΄λ–€ κ²½μš°μ—λ„ λͺ» λ§Œλ“€λ©΄ μ’…λ£Œ
if not removed:
break
r += 1

return r