From 198ae203e78dac0dc438dae732a65bb02de93708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=97=B0=EC=9A=B0?= Date: Wed, 24 Jul 2024 23:42:44 +0900 Subject: [PATCH 01/21] =?UTF-8?q?[week1]=201931=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yeonwoo/18114.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 yeonwoo/18114.py diff --git a/yeonwoo/18114.py b/yeonwoo/18114.py new file mode 100644 index 0000000..05a2fef --- /dev/null +++ b/yeonwoo/18114.py @@ -0,0 +1,30 @@ +# 18114 +# 블랙 프라이데이 + +N, C = map(int, input().split()) # 물건의 개수 N, 제시하는 무게 C + +weight = list(map(int, input().split())) +weight.sort() # 오름차순으로 정렬 + +def find_combination(N, C): + max_index = N - 1 # 제시하는 무게보다 가벼운 최대 무게 + while max_index > 0 and weight[max_index] > C: max_index -= 1 + + # 물건 하나로 조합을 만족하는 경우 + if weight[max_index] == C: return 1 + + # 물건 여러 개로 조합을 만족하는 경우 + left = 0 + right = max_index + while left < right: + diff = C - (weight[left] + weight[right]) # 물건 두 개 무게의 합이 제시된 무게보다 얼마나 부족한지 + if weight[left] + weight[right] == C: return 1 # 두 물건 무게의 합이 C이면 조합을 찾은 것이므로 종료 + elif weight[left] + weight[right] > C: # 두 물건 무게의 합이 제시된 무게보다 크다면 + right -= 1 # 무게의 합을 줄여야 하므로 오른쪽 포인터를 한 칸 왼쪽으로 이동 + else: # 두 물건 무게의 합이 제시된 무게보다 작다면 + if diff in weight[left+1:right]: return 1 # 제시된 무게에서 부족한 값이 두 포인터가 가리키는 물건 사이에 있다면 종료 + left += 1 # 무게의 합을 키워야 하므로 왼쪽 포인터를 한 칸 오른쪽으로 이동 + + return 0 # 조합을 찾지 못함 + +print(find_combination(N, C)) \ No newline at end of file From 1f6dcbb07f169884e02c7b611db81ff24aa43579 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Thu, 25 Jul 2024 00:30:24 +0900 Subject: [PATCH 02/21] =?UTF-8?q?[week1]=201931=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 0 bytes yeonwoo/1931.py | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+) delete mode 100644 .DS_Store create mode 100644 yeonwoo/1931.py diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 7825c257ddbb2efa5c04a624c9673e21b722c6cb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5T0$TO(;SS3OxqAiq=*H@sieh@ZhBpJ*d>i6b;5~>5oB5A!mIUuRe*d zqcgi(u~t25kr|l%W_M;b*>9Kq0RT}S2Acpy0I*OAGd31q2>D58Bx71~h(h&o2>Y-O zw-6jeGtt~Ij||Y<+0ev!t3d-k%%8mUBk7};mPQSA{Z$EC0C~8F4oHY0!BQSXQ_)X9 zNBc>?Yx;inyHVI5l*=z7lg%wG=B>O{u+F_}nRtWtVA!v>d#6-8k}~oqcH2J=J4vg! zyeH#9JB&L$l@JCU3^_Xq<3J{LIgEq8%JsCvvMsw+ER9Ch&GMR4Emy{C&Sn6I5<%1d}2wc@lmJCkd5sgnA+ Date: Thu, 25 Jul 2024 17:51:32 +0900 Subject: [PATCH 03/21] =?UTF-8?q?[week1]=202470=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yeonwoo/2470.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 yeonwoo/2470.py diff --git a/yeonwoo/2470.py b/yeonwoo/2470.py new file mode 100644 index 0000000..9d903d9 --- /dev/null +++ b/yeonwoo/2470.py @@ -0,0 +1,26 @@ +# 2470 +# 두 용액 + +N = int(input()) +water = list(map(int, input().split(' '))) + +water.sort() # 오름차순으로 정렬 +left = 0 # 왼쪽 포인터 +right = N - 1 # 오른쪽 포인터 + +output = [water[left], water[right]] # 특성값이 0에 가장 가까운 용액을 만들어내는 두 용액의 특성값 +while left < right: + + if water[left] + water[right] < 0: # 합이 0보다 작으면 특성값의 합을 키워야 하므로 + left += 1 # 왼쪽 포인터를 오른쪽으로 한 칸 이동 + elif water[left] + water[right] > 0: # 합이 0보다 크면 특성값의 합을 줄여야 하므로 + right -= 1 # 오른쪽 포인터를 왼쪽으로 한 칸 이동 + else: # 합이 0이라면 이미 특성값이 0에 가장 가까운 용액을 찾은 것이므로 + output = [water[left], water[right]] # 결과값을 업데이트하고 종료 + break + + if abs(water[left] + water[right]) < abs(output[0] + output[1]): # 현재 결과값보다 더 0에 가까운 두 용액의 특성값 합을 찾았다면 + output = [water[left], water[right]] # 결과값을 업데이트 + else: break + +print(*(output)) \ No newline at end of file From be7724800e7c0d3c479502ec6fcda3a99e2a4133 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Thu, 25 Jul 2024 17:52:00 +0900 Subject: [PATCH 04/21] =?UTF-8?q?2470=EB=B2=88=20=EB=88=84=EB=9D=BD?= =?UTF-8?q?=EB=90=9C=20=EA=B1=B0=20=EB=8B=A4=EC=8B=9C=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yeonwoo/2470.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/yeonwoo/2470.py b/yeonwoo/2470.py index 9d903d9..4ab70d4 100644 --- a/yeonwoo/2470.py +++ b/yeonwoo/2470.py @@ -11,6 +11,9 @@ output = [water[left], water[right]] # 특성값이 0에 가장 가까운 용액을 만들어내는 두 용액의 특성값 while left < right: + if abs(water[left] + water[right]) < abs(output[0] + output[1]): # 현재 결과값보다 더 0에 가까운 두 용액의 특성값 합을 찾았다면 + output = [water[left], water[right]] # 결과값을 업데이트 + if water[left] + water[right] < 0: # 합이 0보다 작으면 특성값의 합을 키워야 하므로 left += 1 # 왼쪽 포인터를 오른쪽으로 한 칸 이동 elif water[left] + water[right] > 0: # 합이 0보다 크면 특성값의 합을 줄여야 하므로 @@ -19,8 +22,4 @@ output = [water[left], water[right]] # 결과값을 업데이트하고 종료 break - if abs(water[left] + water[right]) < abs(output[0] + output[1]): # 현재 결과값보다 더 0에 가까운 두 용액의 특성값 합을 찾았다면 - output = [water[left], water[right]] # 결과값을 업데이트 - else: break - print(*(output)) \ No newline at end of file From ef299510994fb45c0ab0fa1a0bb3365480bf3701 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Thu, 25 Jul 2024 18:15:26 +0900 Subject: [PATCH 05/21] =?UTF-8?q?[week1]=201449=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yeonwoo/1449.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 yeonwoo/1449.py diff --git a/yeonwoo/1449.py b/yeonwoo/1449.py new file mode 100644 index 0000000..e6f401f --- /dev/null +++ b/yeonwoo/1449.py @@ -0,0 +1,19 @@ +# 1449 +# 수리공 항승 + +N, L = map(int, input().split(' ')) # 물이 새는 곳의 개수 N, 테이프의 길이 L +holes = list(map(int, input().split(' '))) +holes.sort() # 오름차순으로 정렬 + +output = 1 # 필요한 테이프의 수 +tape = [holes[0]-0.5, holes[0]-0.5+L] # 가장 최근에 붙인 테이프가 붙여져 있는 위치 +for i in range(1, N): + # 해당 물이 새는 곳을 이 테이프로 막을 수 있는지 확인 + if holes[i]-0.5 >= tape[0] and holes[i]+0.5 <= tape[1]: # 막을 수 있다면 + continue # 패스 + else: # 막을 수 없다면 + output += 1 # 필요한 테이프를 하나 더 추가 + tape[0] = holes[i]-0.5 + tape[1] = holes[i]-0.5+L + +print(output) \ No newline at end of file From 722babf9576de6a5d88d34db3d52c06f5985f769 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Wed, 7 Aug 2024 23:25:06 +0900 Subject: [PATCH 06/21] =?UTF-8?q?[week4]=2022251=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yeonwoo/20055.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 yeonwoo/20055.py diff --git a/yeonwoo/20055.py b/yeonwoo/20055.py new file mode 100644 index 0000000..2c6689d --- /dev/null +++ b/yeonwoo/20055.py @@ -0,0 +1,34 @@ +# 20055 +# 컨베이어 벨트 위의 로봇 + +from collections import deque + +N, K = map(int, input().split()) +power = deque(map(int, input().split())) # 해당 칸의 내구도 +belt = deque(0 for _ in range(N)) +num = 0 + +while power.count(0) < K: # 내구도가 0인 칸이 K개 이상이라면 종료 + num += 1 # 해당 순서가 몇 번째인지 + + # 벨트가 각 칸 위에 있는 로봇과 함께 회전 + power.rotate(1) + belt.rotate(1) + belt[0] = 0 + + belt[N-1] = 0 # 내리는 위치에 있는 로봇을 내림 + for n in range(N-2, -1, -1): # 벨트에 가장 먼저 올라간 로봇부터 각 칸에 있는 로봇이 이동할 수 있는지 체크 + if belt[n] == 1 and belt[n+1] == 0 and power[n+1] > 0: # 이동하려는 칸에 로봇이 없고, 그 칸의 내구도가 1 이상 남아있어야 이동 가능 + # 로봇이 이동 + belt[n] = 0 + belt[n+1] = 1 + power[n+1] -= 1 + + if power[0] > 0: # 올리는 위치에 있는 칸의 내구도가 0이 아니라면 + belt[0] = 1 # 올리는 칸에 로봇을 올림 + power[0] -= 1 + + # print(power, end=" ") + # print(belt) + +print(num) \ No newline at end of file From c92a37395f1cb97a16559d1f1d5a8fb703bf2440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=97=B0=EC=9A=B0?= Date: Fri, 9 Aug 2024 15:44:55 +0900 Subject: [PATCH 07/21] =?UTF-8?q?=EC=99=9C=EC=9E=90=EA=BE=B8=20=EC=BB=A4?= =?UTF-8?q?=EB=B0=8B=EC=9D=B4=20=EC=95=88=20=EB=90=98=EB=8A=94=20=EA=B1=B0?= =?UTF-8?q?=20=EA=B0=99=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 0 -> 6148 bytes yeonwoo/1449.py | 36 +++++++++++++------------- yeonwoo/1931.py | 40 ++++++++++++++-------------- yeonwoo/20055.py | 66 +++++++++++++++++++++++------------------------ yeonwoo/22251.py | 32 +++++++++++++++++++++++ yeonwoo/2470.py | 48 +++++++++++++++++----------------- 6 files changed, 127 insertions(+), 95 deletions(-) create mode 100644 .DS_Store create mode 100644 yeonwoo/22251.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7825c257ddbb2efa5c04a624c9673e21b722c6cb GIT binary patch literal 6148 zcmeHK%}T>S5T0$TO(;SS3OxqAiq=*H@sieh@ZhBpJ*d>i6b;5~>5oB5A!mIUuRe*d zqcgi(u~t25kr|l%W_M;b*>9Kq0RT}S2Acpy0I*OAGd31q2>D58Bx71~h(h&o2>Y-O zw-6jeGtt~Ij||Y<+0ev!t3d-k%%8mUBk7};mPQSA{Z$EC0C~8F4oHY0!BQSXQ_)X9 zNBc>?Yx;inyHVI5l*=z7lg%wG=B>O{u+F_}nRtWtVA!v>d#6-8k}~oqcH2J=J4vg! zyeH#9JB&L$l@JCU3^_Xq<3J{LIgEq8%JsCvvMsw+ER9Ch&GMR4Emy{C&Sn6I5<%1d}2wc@lmJCkd5sgnA+= tape[0] and holes[i]+0.5 <= tape[1]: # 막을 수 있다면 - continue # 패스 - else: # 막을 수 없다면 - output += 1 # 필요한 테이프를 하나 더 추가 - tape[0] = holes[i]-0.5 - tape[1] = holes[i]-0.5+L - +# 1449 +# 수리공 항승 + +N, L = map(int, input().split(' ')) # 물이 새는 곳의 개수 N, 테이프의 길이 L +holes = list(map(int, input().split(' '))) +holes.sort() # 오름차순으로 정렬 + +output = 1 # 필요한 테이프의 수 +tape = [holes[0]-0.5, holes[0]-0.5+L] # 가장 최근에 붙인 테이프가 붙여져 있는 위치 +for i in range(1, N): + # 해당 물이 새는 곳을 이 테이프로 막을 수 있는지 확인 + if holes[i]-0.5 >= tape[0] and holes[i]+0.5 <= tape[1]: # 막을 수 있다면 + continue # 패스 + else: # 막을 수 없다면 + output += 1 # 필요한 테이프를 하나 더 추가 + tape[0] = holes[i]-0.5 + tape[1] = holes[i]-0.5+L + print(output) \ No newline at end of file diff --git a/yeonwoo/1931.py b/yeonwoo/1931.py index c1d2117..8f89622 100644 --- a/yeonwoo/1931.py +++ b/yeonwoo/1931.py @@ -1,21 +1,21 @@ -# 1931 -# 회의실 배정 - -N = int(input()) - -meetings = [] -for n in range(N): - start, end = map(int, input().split(' ')) - meetings.append([start, end]) - -meetings.sort(key=lambda x:(x[1], x[0])) # 끝나는 시간을 기준으로 정렬 후 시작하는 시간을 기준으로 정렬 -# print(meetings) - -last_time = 0 # 현재 회의가 끝나는 시간 -result = 0 -for meeting in meetings: - if last_time <= meeting[0]: # 해당 회의를 시작할 수 있다면 - result += 1 # 회의 시작 - last_time = meeting[1] # 회의 끝나는 시간 업데이트 - +# 1931 +# 회의실 배정 + +N = int(input()) + +meetings = [] +for n in range(N): + start, end = map(int, input().split(' ')) + meetings.append([start, end]) + +meetings.sort(key=lambda x:(x[1], x[0])) # 끝나는 시간을 기준으로 정렬 후 시작하는 시간을 기준으로 정렬 +# print(meetings) + +last_time = 0 # 현재 회의가 끝나는 시간 +result = 0 +for meeting in meetings: + if last_time <= meeting[0]: # 해당 회의를 시작할 수 있다면 + result += 1 # 회의 시작 + last_time = meeting[1] # 회의 끝나는 시간 업데이트 + print(result) \ No newline at end of file diff --git a/yeonwoo/20055.py b/yeonwoo/20055.py index 2c6689d..03759d9 100644 --- a/yeonwoo/20055.py +++ b/yeonwoo/20055.py @@ -1,34 +1,34 @@ -# 20055 -# 컨베이어 벨트 위의 로봇 - -from collections import deque - -N, K = map(int, input().split()) -power = deque(map(int, input().split())) # 해당 칸의 내구도 -belt = deque(0 for _ in range(N)) -num = 0 - -while power.count(0) < K: # 내구도가 0인 칸이 K개 이상이라면 종료 - num += 1 # 해당 순서가 몇 번째인지 - - # 벨트가 각 칸 위에 있는 로봇과 함께 회전 - power.rotate(1) - belt.rotate(1) - belt[0] = 0 - - belt[N-1] = 0 # 내리는 위치에 있는 로봇을 내림 - for n in range(N-2, -1, -1): # 벨트에 가장 먼저 올라간 로봇부터 각 칸에 있는 로봇이 이동할 수 있는지 체크 - if belt[n] == 1 and belt[n+1] == 0 and power[n+1] > 0: # 이동하려는 칸에 로봇이 없고, 그 칸의 내구도가 1 이상 남아있어야 이동 가능 - # 로봇이 이동 - belt[n] = 0 - belt[n+1] = 1 - power[n+1] -= 1 - - if power[0] > 0: # 올리는 위치에 있는 칸의 내구도가 0이 아니라면 - belt[0] = 1 # 올리는 칸에 로봇을 올림 - power[0] -= 1 - - # print(power, end=" ") - # print(belt) - +# 20055 +# 컨베이어 벨트 위의 로봇 + +from collections import deque + +N, K = map(int, input().split()) +power = deque(map(int, input().split())) # 해당 칸의 내구도 +belt = deque(0 for _ in range(N)) +num = 0 + +while power.count(0) < K: # 내구도가 0인 칸이 K개 이상이라면 종료 + num += 1 # 해당 순서가 몇 번째인지 + + # 벨트가 각 칸 위에 있는 로봇과 함께 회전 + power.rotate(1) + belt.rotate(1) + belt[0] = 0 + + belt[N-1] = 0 # 내리는 위치에 있는 로봇을 내림 + for n in range(N-2, -1, -1): # 벨트에 가장 먼저 올라간 로봇부터 각 칸에 있는 로봇이 이동할 수 있는지 체크 + if belt[n] == 1 and belt[n+1] == 0 and power[n+1] > 0: # 이동하려는 칸에 로봇이 없고, 그 칸의 내구도가 1 이상 남아있어야 이동 가능 + # 로봇이 이동 + belt[n] = 0 + belt[n+1] = 1 + power[n+1] -= 1 + + if power[0] > 0: # 올리는 위치에 있는 칸의 내구도가 0이 아니라면 + belt[0] = 1 # 올리는 칸에 로봇을 올림 + power[0] -= 1 + + # print(power, end=" ") + # print(belt) + print(num) \ No newline at end of file diff --git a/yeonwoo/22251.py b/yeonwoo/22251.py new file mode 100644 index 0000000..e8282da --- /dev/null +++ b/yeonwoo/22251.py @@ -0,0 +1,32 @@ +# 22251 +# 빌런 호석 + +# 바꿀 층수는 N 이하여야 함, 층 자리수 K +# LED 중 최소 1개 최대 P개 반전, 실제 층은 X층 +N, K, P, X = map(int, input().split(' ')) + +LED = [ # 각 숫자에서 불이 들어오는 칸의 위치 + set([0, 1, 2, 4, 5, 6]), + set([2, 5]), + set([0, 2, 3, 4, 6]), + set([0, 2, 3, 5, 6]), + set([1, 2, 3, 5]), + set([0, 1, 3, 5, 6]), + set([0, 1, 3, 4, 5, 6]), + set([0, 2, 5]), + set([0, 1, 2, 3, 4, 5, 6]), + set([0, 1, 2, 3, 5, 6]) +] + +output = 0 # LED를 올바르게 반전시킬 수 있는 경우의 수 +before = [0 for _ in range(K-len(str(X)))] # 실제 층 +before += map(int, list(str(X))) +for n in range(1, N+1): # 최대값까지 + after = [0 for _ in range(K-len(str(n)))] # 실제 층 + after += map(int, list(str(n))) + + num_reverse = 0 # 반전시킨 LED의 수 + for i in range(K): num_reverse += len(LED[before[i]] ^ LED[after[i]]) + if num_reverse <= P: output += 1 + +print(output-1) # 실제 층도 체크되었으므로 1을 빼줌 \ No newline at end of file diff --git a/yeonwoo/2470.py b/yeonwoo/2470.py index 4ab70d4..60b37be 100644 --- a/yeonwoo/2470.py +++ b/yeonwoo/2470.py @@ -1,25 +1,25 @@ -# 2470 -# 두 용액 - -N = int(input()) -water = list(map(int, input().split(' '))) - -water.sort() # 오름차순으로 정렬 -left = 0 # 왼쪽 포인터 -right = N - 1 # 오른쪽 포인터 - -output = [water[left], water[right]] # 특성값이 0에 가장 가까운 용액을 만들어내는 두 용액의 특성값 -while left < right: - - if abs(water[left] + water[right]) < abs(output[0] + output[1]): # 현재 결과값보다 더 0에 가까운 두 용액의 특성값 합을 찾았다면 - output = [water[left], water[right]] # 결과값을 업데이트 - - if water[left] + water[right] < 0: # 합이 0보다 작으면 특성값의 합을 키워야 하므로 - left += 1 # 왼쪽 포인터를 오른쪽으로 한 칸 이동 - elif water[left] + water[right] > 0: # 합이 0보다 크면 특성값의 합을 줄여야 하므로 - right -= 1 # 오른쪽 포인터를 왼쪽으로 한 칸 이동 - else: # 합이 0이라면 이미 특성값이 0에 가장 가까운 용액을 찾은 것이므로 - output = [water[left], water[right]] # 결과값을 업데이트하고 종료 - break - +# 2470 +# 두 용액 + +N = int(input()) +water = list(map(int, input().split(' '))) + +water.sort() # 오름차순으로 정렬 +left = 0 # 왼쪽 포인터 +right = N - 1 # 오른쪽 포인터 + +output = [water[left], water[right]] # 특성값이 0에 가장 가까운 용액을 만들어내는 두 용액의 특성값 +while left < right: + + if abs(water[left] + water[right]) < abs(output[0] + output[1]): # 현재 결과값보다 더 0에 가까운 두 용액의 특성값 합을 찾았다면 + output = [water[left], water[right]] # 결과값을 업데이트 + + if water[left] + water[right] < 0: # 합이 0보다 작으면 특성값의 합을 키워야 하므로 + left += 1 # 왼쪽 포인터를 오른쪽으로 한 칸 이동 + elif water[left] + water[right] > 0: # 합이 0보다 크면 특성값의 합을 줄여야 하므로 + right -= 1 # 오른쪽 포인터를 왼쪽으로 한 칸 이동 + else: # 합이 0이라면 이미 특성값이 0에 가장 가까운 용액을 찾은 것이므로 + output = [water[left], water[right]] # 결과값을 업데이트하고 종료 + break + print(*(output)) \ No newline at end of file From 6e7a27a4e032c96a9b7228dbe6f470888b0a914e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=97=B0=EC=9A=B0?= Date: Fri, 9 Aug 2024 17:11:14 +0900 Subject: [PATCH 08/21] =?UTF-8?q?[week4]=207682=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 6148 bytes yeonwoo/7682.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 yeonwoo/7682.py diff --git a/.DS_Store b/.DS_Store index 7825c257ddbb2efa5c04a624c9673e21b722c6cb..c1ff9ba65567cf6d92a88e0be9babc42b8786c2b 100644 GIT binary patch delta 627 zcmZWnzi-n}5Wce;;*^#+t(_9VQ1F6i1qO;*38A)OfC!;PZB;q6U~K0lm^kmbw%d?K zQI;-rBFfCfgv5d}Fmz+$pFnJ^upu_=IH3aGaNl?LzWYw^$B}xZzRq$JlfAuc@7g6y zd?=mZTbJiB(VyZv__2S??RDqc?OQ9$i}TC3JB#z}m8BaYRd04WDM41Q-`UXXPJ^;n zFkFZ+!t@Boa2%2(w15Bu3e7Mw+d6PfhnWEQ$#fmt4^;K5C?dyCB+ev-)a2Qz>2qnZ zo0*x-NEum{vvczKT<(G{&YFf*uX${rR_-x}d3k4_?9@EFvgsO@O>0^}UIv@?A<@N| zf213v^7OQ{)pA3PbXpkN-S-HgL%(9R>UT+?{Ygkr*2T1MdCYN2%(nxZ(ekeUoHYvp zX%uLcg(DAa(k!~smcLCrKg9ofw6fuO2Cb2N>xpBS#3|A|3j)@Nl#!doXvrgyQ&+RY zBsz_<`XjzhW$odZT#1PYN=yI*Y0O55Ta;0fN-1llQAL0SScgZj4Rtt#9=w5fZ~~v< z3w(!Pn8X}j#syr$ySR!Eu3`ZnqmIweh}*gG8(;i;5WeW=`EP@ykQTx(H8A*}d_OI% O3!$8glmktA&;JH93Y=sB delta 119 zcmZoMXfc=|#>B)qu~2NHo+2a5#(>?7j4YFRSZWz}OzvVSRF|l(Ha0ZSQ7|?zs?|}b zwlo5=O^nTIYdJYYmG!NI; X가 승리 or 무승부 + if check(test, 'X'): # X가 성공한 경우 + if check(test, 'O'): outputs.append('invalid') # O도 성공했으면 invalid + else: outputs.append('valid') # O가 실패했어야 가능 + else: # X가 실패한 경우 + if num_X + num_O < 9: outputs.append('invalid') # 게임판을 모두 채우지 못했으면 invalid + elif check(test, 'O'): outputs.append('invalid') # O가 성공했으면 invalid + else: outputs.append('valid') # O가 실패했어야 가능 + elif num_X == num_O: # X와 O의 개수가 같음 -> O가 승리 + if check(test, 'O'): # O가 성공한 경우 + if check(test, 'X'): outputs.append('invalid') # X도 성공했으면 invalid + else: outputs.append('valid') # X가 실패했어야 가능 + else: # O가 실패한 경우 + outputs.append('invalid') # 불가능 + else: # 나머지 -> 불가능 + outputs.append('invalid') + +for output in outputs: print(output) \ No newline at end of file From 3cc0f1ea6dabdc66df63d66d4b5f29b5d2e6d2a5 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Sat, 10 Aug 2024 17:47:09 +0900 Subject: [PATCH 09/21] =?UTF-8?q?[week4]=207682=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 0 bytes yeonwoo/17144.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) delete mode 100644 .DS_Store create mode 100644 yeonwoo/17144.py diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index c1ff9ba65567cf6d92a88e0be9babc42b8786c2b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKPfrs;6n_K7Zb4*$Rv>!V*oz4SK{1dRLn#n#41rLBMZmJ#4s~Ta)9h}kKuCJk zn;*ar;K`#0Z=U=F-i#kXub%YH>};S^y=lbkOJ;s=-k+I$zwOR+0Dxrc5nzjiR2M=gc>4MqQa;mnnv9J+xVwH?q9W%AU;4 z2M#TvC5rmc(b27$=`mya_VJi;G&41c>cq|C&#NL*%vR!T#ie4Vf{nVUB|ZB!;4+L9vs3;cm=QF9ejXK@CCk+I2j?=$S9d2cgZZdPjciDDUuyx2H73q z`@Pz_4ta{>Gw*jl?=pw83VOn<)}(VdQiW(e=kVF1M~)bX82Gaci2cF9CNQJ08KB%c zu#;B+#2A{Tpf3I}h#W&WV>vbhH~PE~Bs+V2}<(T|S6fnW!5I zk*nkUh71Ri2{7s-1|kMp8R!g#x;XzAe|`UNO^QYl0}%uN6$2!;kYC7RN$PBED^8rX w2DTk+LPT6MK$(J_I*z3xj^bf#QqX4z1u>(r86a9vqCWzXhNz1e_^S;3019j3Hvj+t diff --git a/yeonwoo/17144.py b/yeonwoo/17144.py new file mode 100644 index 0000000..a48debb --- /dev/null +++ b/yeonwoo/17144.py @@ -0,0 +1,66 @@ +# 17144 +# 미세먼지 안녕! + +from copy import deepcopy + +R, C, T = map(int, input().split(' ')) # 격자판 RxC, T초 후의 상태 +next_room = [] # 다음에 변화될 상태 +for _ in range(R): next_room.append(list(map(int, input().split(' ')))) +dir = [[-1, 0], [0, 1], [1, 0], [0, -1]] # 동서남북 방향 + +room = [] +air_purifier = [] # 공기청정기 위치 +for _ in range(T): # T초 동안 진행됨 + room = deepcopy(next_room) + # 미세먼지 확산 + for r in range(R): + for c in range(C): + if room[r][c] > 0: # 해당 칸에 미세먼지가 있다면 + # 각 방향에 위치한 칸이 벽이 아니고, 공기청정기가 없다면 미세먼지 확산 + if r > 0 and room[r-1][c] > -1: + next_room[r-1][c] += room[r][c] // 5 + next_room[r][c] -= room[r][c] // 5 + if c > 0 and room[r][c-1] > -1: + next_room[r][c-1] += room[r][c] // 5 + next_room[r][c] -= room[r][c] // 5 + if r < R-1 and room[r+1][c] > -1: + next_room[r+1][c] += room[r][c] // 5 + next_room[r][c] -= room[r][c] // 5 + if c < C-1 and room[r][c+1] > -1: + next_room[r][c+1] += room[r][c] // 5 + next_room[r][c] -= room[r][c] // 5 + elif room[r][c] == -1: air_purifier.append([r, c]) + + # 공기청정기 작동, 바람 순환 + # 반시계 방향 순환 + air_move = [] + r, c = air_purifier[0][0], air_purifier[0][1] + for i in range(c+1, C-1): air_move.append([r, i]) + for i in range(r, 0, -1): air_move.append([i, C-1]) + for i in range(C-1, c, -1): air_move.append([0, i]) + for i in range(0, r): air_move.append([i, c]) + # print(air_move) + for i in range(len(air_move)-1, 0, -1): + next_room[air_move[i][0]][air_move[i][1]] = next_room[air_move[i-1][0]][air_move[i-1][1]] + next_room[air_move[0][0]][air_move[0][1]] = 0 + + # 시계 방향 순환 + air_move = [] + r, c = air_purifier[1][0], air_purifier[1][1] + for i in range(c+1, C-1): air_move.append([r, i]) + for i in range(r, R-1): air_move.append([i, C-1]) + for i in range(C-1, c, -1): air_move.append([R-1, i]) + for i in range(R-1, r, -1): air_move.append([i, c]) + # print(air_move) + for i in range(len(air_move)-1, 0, -1): + next_room[air_move[i][0]][air_move[i][1]] = next_room[air_move[i-1][0]][air_move[i-1][1]] + next_room[air_move[0][0]][air_move[0][1]] = 0 + + # for r in range(R): print(next_room[r]) + +result = 0 +for r in range(R): + for c in range(C): + if next_room[r][c] > 0: # 미세먼지가 있다면 + result += next_room[r][c] # 해당 미세먼지 값을 합산 +print(result) \ No newline at end of file From d1e0cc3784f62e8f037c29e77927361309837b0e Mon Sep 17 00:00:00 2001 From: only4wxx Date: Sat, 10 Aug 2024 19:18:22 +0900 Subject: [PATCH 10/21] =?UTF-8?q?[week5]=202606=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2606.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 2606.py diff --git a/2606.py b/2606.py new file mode 100644 index 0000000..80976c4 --- /dev/null +++ b/2606.py @@ -0,0 +1,25 @@ +# 2606 +# 바이러스 + +from collections import deque + +computer = set([1]) # 1번 컴퓨터를 통해 웜 바이러스에 걸리게 되는 컴퓨터의 수 + +num_computer = int(input()) +N = int(input()) +computer = [ [] for _ in range(num_computer) ] # 각 컴퓨터와 연결되어 있는 컴퓨터 +for _ in range(N): + com1, com2 = map(int, input().split(' ')) + computer[com1-1].append(com2-1) + computer[com2-1].append(com1-1) +# print(computer) + +visited = [] # 이미 체크한 컴퓨터 +queue = deque([0]) # 1번 컴퓨터를 통해 웜 바이러스에 걸리게 되는 컴퓨터 +while queue: + start = queue.popleft() + if start not in visited: # 체크 안 한 컴퓨터라면 + visited.append(start) + for com in computer[start]: queue.append(com) + +print(len(visited)-1) # 1번 컴퓨터를 통해 웜 바이러스에 걸리게 되는 컴퓨터의 수 \ No newline at end of file From 5d653dab6368e294a2f03a71fdc6f1100426ca88 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Sat, 10 Aug 2024 22:05:45 +0900 Subject: [PATCH 11/21] =?UTF-8?q?[week5]=201260=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1260.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 1260.py diff --git a/1260.py b/1260.py new file mode 100644 index 0000000..503770e --- /dev/null +++ b/1260.py @@ -0,0 +1,34 @@ +# 1260 +# DFS와 BFS + +from collections import deque + +DFS_visited = [] # DFS를 수행한 결과 +def dfs(graph, start): + if start in DFS_visited: return # 이미 방문한 노드 + + DFS_visited.append(start) + for node in graph[start]: dfs(graph, node) # 해당 노드와 연결된 노드로 DFS를 계속함 + +BFS_visited = [] # BFS를 수행한 결과 +def bfs(graph, start): + queue = deque([start]) + while queue: + node = queue.popleft() + if node not in BFS_visited: # 아직 방문한 적 없는 노드만 탐색 + BFS_visited.append(node) + for n in graph[node]: queue.append(n) + + +N, M, V = map(int, input().split(' ')) +graph = [ [] for _ in range(N+1) ] # 각 정점과 연결된 정점들 +for _ in range(M): + n1, n2 = map(int, input().split(' ')) + graph[n1].append(n2) + graph[n2].append(n1) +for n in range(1, N+1): graph[n].sort() + +dfs(graph, V) +bfs(graph, V) +print(*(DFS_visited)) +print(*(BFS_visited)) \ No newline at end of file From efff236dcbac0da60516f9b0db639d165473d6f5 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Sat, 10 Aug 2024 23:34:57 +0900 Subject: [PATCH 12/21] =?UTF-8?q?[week5]=2011725=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 11725.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 11725.py diff --git a/11725.py b/11725.py new file mode 100644 index 0000000..16da94d --- /dev/null +++ b/11725.py @@ -0,0 +1,31 @@ +# 11725 +# 트리의 부모 찾기 + +from collections import deque + +def find_parent(graph, start): + parent = [0 for _ in range(len(graph))] # 각 노드의 부모 노드 + visited = [] # 탐색한 노드를 체크하기 위해 + queue = deque([start]) + while queue: + node = queue.popleft() + visited.append(node) + for n in graph[node]: + if not parent[n]: # 아직 탐색하지 않은 노드라면(부모 노드가 설정되지 않은 노드라면) + queue.append(n) + parent[n] = node # 해당 노드의 부모 노드를 설정 + + # print(node, end=' ') + # print(parent, end=' ') + # print(queue) + return parent + +N = int(input()) +graph = [ [] for _ in range(N+1) ] # 각 노드와 연결된 노드들 +for _ in range(N-1): + n1, n2 = map(int, input().split(' ')) + graph[n1].append(n2) + graph[n2].append(n1) + +parent = find_parent(graph, 1) +for i in range(2, N+1): print(parent[i]) \ No newline at end of file From 792441507920a276b790076e6c053031160c8eca Mon Sep 17 00:00:00 2001 From: only4wxx Date: Mon, 12 Aug 2024 20:18:44 +0900 Subject: [PATCH 13/21] =?UTF-8?q?[week5]=201325=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1325.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 1325.py diff --git a/1325.py b/1325.py new file mode 100644 index 0000000..953ba14 --- /dev/null +++ b/1325.py @@ -0,0 +1,42 @@ +# 1325 +# 효율적인 해킹 + +from collections import deque + +N, M = map(int, input().split(' ')) # N개의 컴퓨터, M개 줄 입력 +trust = [ [] for _ in range(N+1) ] # 각 컴퓨터를 신뢰하는 컴퓨터들. 해당 컴퓨터를 해킹하면 함께 해킹할 수 있는 컴퓨터 +for _ in range(M): + A, B = map(int, input().split(' ')) # A가 B를 신뢰 + trust[B].append(A) # B를 해킹하면 A도 해킹할 수 있음 +# for n in range(1, len(trust)): +# print(n, end=" ") +# print(trust[n]) + +outputs = [] +max_hacking = 0 +def bfs(trust, start): + global max_hacking + result = 0 # 해당 컴퓨터를 해킹하면 한 번에 해킹할 수 있는 모든 컴퓨터의 개수 + visited = [False] * (N+1) + queue = deque([start]) + visited[start] = True + while queue: + # print(hacking[start]) + # print(queue) + computer = queue.popleft() + for com in trust[computer]: + if not visited[com]: + visited[com] = True + result += 1 + queue.append(com) + if result > max_hacking: + outputs.clear() + outputs.append(start) + max_hacking = result + elif result == max_hacking: outputs.append(start) + +for computer in range(1, N+1): bfs(trust, computer) +# print(hacking) + +# 한 번에 가장 많은 컴퓨터를 해킹할 수 있는 컴퓨터를 찾음 +print(*(outputs)) \ No newline at end of file From 75ad3350287cfda426e5066f9c8ff60cf7c2d7a5 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Mon, 12 Aug 2024 20:19:19 +0900 Subject: [PATCH 14/21] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=9C=84=EC=B9=98?= =?UTF-8?q?=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 11725.py => yeonwoo/11725.py | 0 1260.py => yeonwoo/1260.py | 0 1325.py => yeonwoo/1325.py | 0 2606.py => yeonwoo/2606.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename 11725.py => yeonwoo/11725.py (100%) rename 1260.py => yeonwoo/1260.py (100%) rename 1325.py => yeonwoo/1325.py (100%) rename 2606.py => yeonwoo/2606.py (100%) diff --git a/11725.py b/yeonwoo/11725.py similarity index 100% rename from 11725.py rename to yeonwoo/11725.py diff --git a/1260.py b/yeonwoo/1260.py similarity index 100% rename from 1260.py rename to yeonwoo/1260.py diff --git a/1325.py b/yeonwoo/1325.py similarity index 100% rename from 1325.py rename to yeonwoo/1325.py diff --git a/2606.py b/yeonwoo/2606.py similarity index 100% rename from 2606.py rename to yeonwoo/2606.py From 95fed8279ca15d87e81c1d566f2cca37143eb801 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Mon, 12 Aug 2024 21:21:40 +0900 Subject: [PATCH 15/21] =?UTF-8?q?[week6]=201283=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yeonwoo/1283.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 yeonwoo/1283.py diff --git a/yeonwoo/1283.py b/yeonwoo/1283.py new file mode 100644 index 0000000..803f1f9 --- /dev/null +++ b/yeonwoo/1283.py @@ -0,0 +1,41 @@ +# 1283 +# 단축키 지정 + +N = int(input()) + +shortcut = [] # 각 옵션의 단축키와, 해당 위치 +def assign_shortcut(option): + shortcut_key = list(map(lambda x: x[0], shortcut)) # 단축키들 + # print(shortcut_key) + option = option.upper() # 대문자로 변환 + + for i in range(len(option)): + if i == 0 or option[i-1] == ' ': # 단어의 첫 글자 + if option[i] not in shortcut_key: # 단어의 첫 글자가 단축키로 지정되어 있지 않다면 + shortcut.append([option[i], i]) # 단축키와 해당 위치를 리스트에 저장 + return + + # 모든 단어의 첫 글자가 이미 단축키로 지정되어 있다면 + for i in range(len(option)): + if option[i] != ' ' and option[i] not in shortcut_key: # 왼쪽에서부터 차례대로 알파벳을 보면서 단축키로 지정 안 된 것이 있다면 + shortcut.append([option[i], i]) # 단축키로 지정 + return + + # 어떠한 것도 단축키로 지정할 수 없다면 그냥 놔둠 + shortcut.append(['', -1]) + +options = [] +for _ in range(N): + option = input() + assign_shortcut(option) + options.append(option) +# print(shortcut) + +for n in range(N): # 각 옵션에 단축키를 표시해서 출력 + index = shortcut[n][1] # 단축키가 있는 위치 + + for i in range(len(options[n])): # 출력 + if i == index: # 단축키가 있는 알파벳을 출력할 때 + print('['+options[n][i]+']', end='') + else: print(options[n][i], end='') + print() \ No newline at end of file From c5559834d98fd20ca45a308206e183b547159bb2 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Mon, 12 Aug 2024 21:42:34 +0900 Subject: [PATCH 16/21] =?UTF-8?q?[week6]=201051=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yeonwoo/1051.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 yeonwoo/1051.py diff --git a/yeonwoo/1051.py b/yeonwoo/1051.py new file mode 100644 index 0000000..5123bbc --- /dev/null +++ b/yeonwoo/1051.py @@ -0,0 +1,26 @@ +# 1051 +# 숫자 정사각형 + +def find_square(n, m): + number = rectangle[n][m] # 기준이 될 숫자 + edge = 1 # 변의 길이 + max_edge = 0 # 정사각형의 변 길이 최대값 + while n+edge< N and m+edge < M: # 직사각형 안에서 진행 + if number == rectangle[n+edge][m] == rectangle[n][m+edge] == rectangle[n+edge][m+edge]: # 꼭짓점에 쓰여 있는 수가 모두 같은 정사각형을 찾는다면 + max_edge = edge + edge += 1 + return max_edge + +N, M = map(int, input().split(' ')) +rectangle = [] +for _ in range(N): + rectangle.append(list(input())) +# print(rectangle) + +result_edge = 0 +for n in range(N): + for m in range(M): + # 모든 위치에서 시작하여 정사각형을 찾음 + max_edge = find_square(n, m) + if max_edge > result_edge: result_edge = max_edge +print((result_edge+1)**2) \ No newline at end of file From 98204c81f76100690c46c62986242fc740913560 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Fri, 16 Aug 2024 00:16:24 +0900 Subject: [PATCH 17/21] =?UTF-8?q?[week6]=2017413=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yeonwoo/17276.py | 3 +++ yeonwoo/17413.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 yeonwoo/17276.py create mode 100644 yeonwoo/17413.py diff --git a/yeonwoo/17276.py b/yeonwoo/17276.py new file mode 100644 index 0000000..5d537cf --- /dev/null +++ b/yeonwoo/17276.py @@ -0,0 +1,3 @@ +# 17276 +# 배열 돌리기 + diff --git a/yeonwoo/17413.py b/yeonwoo/17413.py new file mode 100644 index 0000000..22b0867 --- /dev/null +++ b/yeonwoo/17413.py @@ -0,0 +1,32 @@ +# 17413 +# 단어 뒤집기 + +string = input() + +stack = [] # '<', '>', 문자를 담을 스택 +result = [] # 결과 문자열 +for element in string: + if element == '<': + while stack: result.append(stack.pop()) # 단어를 뒤집어서 저장 + stack.append('<') + result.append('<') + elif element == '>': + stack.pop() # 여기까지 태그 + result.append('>') + elif element == ' ': + if stack and stack[0] == '<': # 태그라면 + result.append(' ') # 뒤집기 없이 저장 + else: # 단어라면 + while stack: result.append(stack.pop()) # 단어를 뒤집어서 저장 + result.append(' ') + else: # 문자 + if stack and stack[0] == '<': # 태그라면 + result.append(element) # 뒤집지 않고 저장 + else: # 단어라면 + stack.append(element) +if stack and stack[0] == '<': + result.append('>') +else: + while stack: result.append(stack.pop()) # 단어를 뒤집어서 저장 + +print(''.join(result)) \ No newline at end of file From 445f1d7d2b17d9b98edd4c9f39e2b0cd7b862142 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Fri, 16 Aug 2024 01:02:05 +0900 Subject: [PATCH 18/21] =?UTF-8?q?[week6]=2017276=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yeonwoo/17276.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/yeonwoo/17276.py b/yeonwoo/17276.py index 5d537cf..f02a70b 100644 --- a/yeonwoo/17276.py +++ b/yeonwoo/17276.py @@ -1,3 +1,31 @@ # 17276 # 배열 돌리기 +from copy import deepcopy + +def rotate_45(array, n): # 배열을 시계 방향으로 45도 돌리는 함수 + result_array = deepcopy(array) + for i in range(n): + result_array[i][(n+1)//2-1] = array[i][i] # 주 대각선을 가운데 열로 옮김 + result_array[i][n-1-i] = array[i][(n+1)//2-1] # 가운데 열을 부 대각선으로 옮김 + result_array[(n+1)//2-1][n-1-i] = array[i][n-1-i] # 부 대각선을 가운데 행으로 옮김 + result_array[i][i] = array[(n+1)//2-1][i] # 가운데 행을 주 대각선으로 옮김 + return result_array + +N = int(input()) # 테스트 케이스의 개수 +result = [] # 결과값 리스트 +for _ in range(N): + n, d = map(int, input().split(' ')) + array = [] + for _ in range(n): + array.append(list(map(int, input().split(' ')))) + + if d < 0: d += 360 # 함수를 사용하기 위해 360도를 더해줌 + number = d // 45 # 45도로 몇 번 돌려야 하는지 + for _ in range(number): + result_array = rotate_45(array, n) + array = deepcopy(result_array) + + for i in range(n): result.append(array[i]) + +for i in range(len(result)): print(*(result[i])) \ No newline at end of file From 603b607a2b04a416e4afffb49b607460c7f9b657 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Sat, 17 Aug 2024 00:00:19 +0900 Subject: [PATCH 19/21] =?UTF-8?q?[week6]=2020164=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yeonwoo/20164.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 yeonwoo/20164.py diff --git a/yeonwoo/20164.py b/yeonwoo/20164.py new file mode 100644 index 0000000..f6bb2c9 --- /dev/null +++ b/yeonwoo/20164.py @@ -0,0 +1,37 @@ +# 20164 +# 홀수 홀릭 호석 + +from itertools import combinations + +result = [20, 0] # 결과 최솟값, 최댓값 +def make_odd(number, res): # 로직을 실행 + + if len(number) == 1: # 수가 한 자리 + if int(number) % 2 == 1: # 홀수라면 + res += 1 + + if res < result[0]: result[0] = res # 최솟값인지 체크 + if res > result[1]: result[1] = res # 최댓값인지 체크 + + elif len(number) == 2: # 수가 두 자리 + for num in number: # 홀수의 개수를 셈 + if int(num) % 2 == 1: # 홀수라면 + res += 1 + + new_number = str(int(number[0]) + int(number[1])) # 2개로 나눠서 합을 구하여 새로운 수로 생각 + make_odd(new_number, res) + + else: # 수가 세 자리 이상 + for num in number: # 홀수의 개수를 셈 + if int(num) % 2 == 1: # 홀수라면 + res += 1 + + section = list(combinations([i for i in range(1, len(number))], 2)) # 수를 분할시키는 위치의 경우의 수 + # print(section) + for s1, s2 in section: + new_number = str(int(number[:s1]) + int(number[s1:s2]) + int(number[s2:])) # 3개로 나눠서 합을 구하여 새로운 수로 생각 + make_odd(new_number, res) + +N = str(input()) # 문자열로 입력을 받음 +make_odd(N, 0) +print(*(result)) \ No newline at end of file From 43be4ae7de734e7e4786ca7fa15aaf4282a631d1 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Tue, 20 Aug 2024 00:03:39 +0900 Subject: [PATCH 20/21] =?UTF-8?q?[week6]=203085=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yeonwoo/3085.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 yeonwoo/3085.py diff --git a/yeonwoo/3085.py b/yeonwoo/3085.py new file mode 100644 index 0000000..fcd4709 --- /dev/null +++ b/yeonwoo/3085.py @@ -0,0 +1,57 @@ +# 3085 +# 사탕 게임 + +from copy import deepcopy + +result = 0 +def check_candy(candy): + global result + + for x in range(N): + color = '' + + # 행 체크 + number = 0 + for y in range(N): + if candy[x][y] == color: # 연속된 사탕이라면 + number += 1 + else: # 연속된 사탕이 아니라면 + if result < number: result = number # 최대 개수 업데이트 + number = 1 # 처음부터 다시 셈 + color = candy[x][y] + if result < number: result = number # 최대 개수 업데이트 + + # 열 체크 + number = 0 + for y in range(N): + if candy[y][x] == color: # 연속된 사탕이라면 + number += 1 + else: # 연속된 사탕이 아니라면 + if result < number: result = number # 최대 개수 업데이트 + number = 1 # 처음부터 다시 셈 + color = candy[y][x] + if result < number: result = number # 최대 개수 업데이트 + +N = int(input()) +candy = [] +for _ in range(N): + candy.append(list(input())) +# print(candy) + +for x in range(N): + for y in range(N): + # 행을 바꿈 + if x < N-1: + ex_candy = deepcopy(candy) + ex_candy[x][y], ex_candy[x+1][y] = candy[x+1][y], candy[x][y] + # for i in range(len(ex_candy)): print(ex_candy[i]) + check_candy(ex_candy) + + # 열을 바꿈 + if y < N-1: + ex_candy = deepcopy(candy) + ex_candy[x][y], ex_candy[x][y+1] = candy[x][y+1], candy[x][y] + # for i in range(len(ex_candy)): print(ex_candy[i]) + check_candy(ex_candy) + +print(result) \ No newline at end of file From 9978f86a381a6802ff378561737ac9b6334f2ce5 Mon Sep 17 00:00:00 2001 From: only4wxx Date: Thu, 22 Aug 2024 16:01:30 +0900 Subject: [PATCH 21/21] =?UTF-8?q?[week6]=2014500=EB=B2=88=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yeonwoo/14500.py | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 yeonwoo/14500.py diff --git a/yeonwoo/14500.py b/yeonwoo/14500.py new file mode 100644 index 0000000..1caf2c8 --- /dev/null +++ b/yeonwoo/14500.py @@ -0,0 +1,82 @@ +# 14500 +# 테트로미노 + +N, M = map(int, input().split(' ')) +paper = [] +for _ in range(N): paper.append(list(map(int, input().split(' ')))) +# print(paper) + +max_num = 0 +for n in range(N): + for m in range(M): + + # 1번 테트로미노 + if m+3 < M: + num = paper[n][m] + paper[n][m+1] + paper[n][m+2] + paper[n][m+3] + if num > max_num: max_num = num + if n+3 < N: + num = paper[n][m] + paper[n+1][m] + paper[n+2][m] + paper[n+3][m] + if num > max_num: max_num = num + + # 2번 테트로미노 + if n+1 < N and m+1 < M: + num = paper[n][m] + paper[n][m+1] + paper[n+1][m] + paper[n+1][m+1] + if num > max_num: max_num = num + + # 3번 테트로미노 + if n+2 < N: + if m+1 < M: + num = paper[n][m] + paper[n+1][m] + paper[n+2][m] + paper[n][m+1] + if num > max_num: max_num = num + + num = paper[n][m] + paper[n+1][m] + paper[n+2][m] + paper[n+2][m+1] + if num > max_num: max_num = num + if m-1 > -1: + num = paper[n][m] + paper[n+1][m] + paper[n+2][m] + paper[n][m-1] + if num > max_num: max_num = num + + num = paper[n][m] + paper[n+1][m] + paper[n+2][m] + paper[n+2][m-1] + if num > max_num: max_num = num + if m+2 < M: + if n+1 < N: + num = paper[n][m] + paper[n][m+1] + paper[n][m+2] + paper[n+1][m] + if num > max_num: max_num = num + + num = paper[n][m] + paper[n][m+1] + paper[n][m+2] + paper[n+1][m+2] + if num > max_num: max_num = num + if n-1 > -1: + num = paper[n][m] + paper[n][m+1] + paper[n][m+2] + paper[n-1][m] + if num > max_num: max_num = num + + num = paper[n][m] + paper[n][m+1] + paper[n][m+2] + paper[n-1][m+2] + if num > max_num: max_num = num + + # 4번 테트로미노 + if n+2 < N and m+1 < M: + num = paper[n][m] + paper[n+1][m] + paper[n+1][m+1] + paper[n+2][m+1] + if num > max_num: max_num = num + + num = paper[n][m+1] + paper[n+1][m] + paper[n+1][m+1] + paper[n+2][m] + if num > max_num: max_num = num + if n+1 < N and m+2 < M: + num = paper[n][m+1] + paper[n][m+2] + paper[n+1][m] + paper[n+1][m+1] + if num > max_num: max_num = num + + num = paper[n][m] + paper[n][m+1] + paper[n+1][m+1] + paper[n+1][m+2] + if num > max_num: max_num = num + + # 5번 테트로미노 + if n+1 < N and m+2 < M: + num = paper[n][m] + paper[n][m+1] + paper[n][m+2] + paper[n+1][m+1] + if num > max_num: max_num = num + + num = paper[n+1][m] + paper[n+1][m+1] + paper[n+1][m+2] + paper[n][m+1] + if num > max_num: max_num = num + if n+2 < N and m+1 < M: + num = paper[n][m] + paper[n+1][m] + paper[n+2][m] + paper[n+1][m+1] + if num > max_num: max_num = num + + num = paper[n][m+1] + paper[n+1][m+1] + paper[n+2][m+1] + paper[n+1][m] + if num > max_num: max_num = num + +print(max_num) \ No newline at end of file