알고리즘 문제풀이
Swea D4 자기방으로 돌아가기 Python
아크몽
2024. 2. 29. 10:42
필요한 내용 : 아랫 방을 윗방으로 변경하는 코드, 시작점과 끝점을 바꿔주는 코드
정답 풀이
t = int(input())
for tc in range(1,t+1):
n = int(input())
arr = []
count = [0] * 401
for _ in range(n):
arr.append(tuple(map(int,input().split())))
# print(arr)
for i in arr:
s,e = i
# 아랫방을 윗방으로 변경
if s%2 ==0: s -= 1
if e%2 ==0: e -= 1
if s > e: s, e = e, s # swap
for j in range(s,e+1):
count[j] +=1
# print(count)
print(f'#{tc} {max(count)}')
2개만 맞는 풀이
t = int(input())
for tc in range(1,t+1):
n = int(input())
arr = []
count = [0] * 401
for _ in range(n):
arr.append(tuple(map(int,input().split())))
# print(arr)
for i in arr:
s,e = i
for j in range(s,e+1):
count[j] +=1
# print(count)
print(f'#{tc} {max(count)}')
9개만 맞는 풀이
t = int(input())
for tc in range(1,t+1):
n = int(input())
arr = []
count = [0] * 401
for _ in range(n):
arr.append(tuple(map(int,input().split())))
# print(arr)
for i in arr:
s,e = i
if s > e: s, e = e, s # swap
for j in range(s,e+1):
count[j] +=1
# print(count)
print(f'#{tc} {max(count)}')