白駿1931号:会議室の手配
2471 ワード
問題解決の考え方
import sys
N = int(input())
conf = {}
numbers = set()
for _ in range(N):
a, b = map(int, sys.stdin.readline().split())
try:
conf[a].append(b)
except:
conf[a] = [b]
numbers.add(a)
if N == 1:
print("1")
sys.exit()
answer = 0
min_end = -1
for n in numbers:
conf[n] = sorted(conf[n])
tf = 0
for n in numbers:
count = 1
same_count = 0
start = n
end = conf[start][0]
if end < min_end or min_end == -1:
min_end = end
if start >= min_end and len(numbers) != 1:
continue
while end <= max(numbers):
try:
tmp = end
end = conf[end][same_count]
start = tmp
count += 1
if start == end:
tf = 1
same_count += 1
else:
same_count = 0
except:
same_count = 0
end += 1
if count > answer:
answer = count
if tf:
print(answer - 1)
else:
print(answer)
N = int(input())
conf = []
for _ in range(N):
start, end = map(int, input().split())
conf.append([start, end])
conf = sorted(conf, key=lambda a: a[0]) #이렇게 처리하면, 원하는 요소를 기준으로 정렬할 수 있다.
conf = sorted(conf, key=lambda a: a[1])
last = 0
count = 0
for i, j in conf:
if i >= last:
count += 1
last = j
print(count)
手で問題を解くのではなく、頭で問題を解くように努力しましょう.
✔関連概念
カウンタモジュール、Dictionary、Tuple、Set、Listなどの機能を適切に使用すると効率が向上します.
あまりにも不適切な場所に無理やり使う傾向がある.選択の練習が必要です!
Reference
この問題について(白駿1931号:会議室の手配), 我々は、より多くの情報をここで見つけました https://velog.io/@dlehdtjq00/백준-1931번-회의실-배정テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol