๋ฌธ์
๋ฐฑ์ค ์จ๋ผ์ธ ์ ์ง - 20006๋ฒ
ํ์ด ๊ณผ์
๋ญํน ๋๊ธฐ์ด ๋ก์ง์ ๊ตฌํํ๋ ๋ฌธ์ ์
๋๋ค.
๋จผ์ ๋ฐฉ์ ์ ๋ณด๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์ํด ํด์ ํ
์ด๋ธ
์ ์ฌ์ฉํ์ต๋๋ค.
์ด๋ ํด๋น ๋ฐฉ์ ๋ฐฉ์ฅ์ ์๋ณ์์ ์ฐธ์ฌ์ค์ธ ๋ค๋ฅธ ์ฌ๋๋ค์ ๋ฐฐ์ด ํํ๋ก ๊ด๋ฆฌํฉ๋๋ค.
์ฌ๊ธฐ์ assign_player
ํจ์์์๋ ํ๋ ์ด์ด๋ฅผ ๊ธฐ์กด์ ์กด์ฌํ๋ ๋ฐฉ์ ํ ๋น ๊ฐ๋ฅํ์ง ํ๋จํ๊ณ
๋ง์ฝ ์๋ก์ด ๋ฐฉ์ด ํ์ํ ๊ฒฝ์ฐ ๋ฐฉ์ฅ์ผ๋ก ํ ๋นํ ๋ค ์๋ก์ด ๋ฐฉ์ ์์ฑํ๋๋ก ํฉ๋๋ค.
์ฝ๋
import sys
def assign_player(player_id, player_level, rooms):
for _, meta in rooms.items():
master_level = players[meta['master']]
if master_level - 10 <= player_level <= master_level + 10 and len(meta['participant']) < M - 1:
meta['participant'].append(player_id)
return True
return False
def solution():
rooms = {}
for player_id, player_level in players.items():
if not assign_player(player_id, int(player_level), rooms):
rooms[len(rooms)] = {'master': player_id, 'participant': []}
for room_id in rooms:
master = rooms[room_id]['master']
participants = rooms[room_id]['participant']
if len(participants) == M - 1:
print('Started!')
else:
print('Waiting!')
for player in sorted(participants + [master]):
print(f"{players[player]} {player}")
if __name__ == '__main__':
P, M = list(map(int, sys.stdin.readline().split()))
players = {}
for _ in range(P):
level, id = list(sys.stdin.readline().split())
players[id] = int(level)
solution()
๋ฐ์ํ
'๐ algorithm > boj' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ 16441 - ์๊ธฐ๋ผ์ง์ ๋๋ (0) | 2021.04.13 |
---|---|
BOJ 1922 - ๋คํธ์ํฌ ์ฐ๊ฒฐ (0) | 2021.04.13 |
BOJ 2869 - ๋ฌํฝ์ด๋ ์ฌ๋ผ๊ฐ๊ณ ์ถ๋ค (0) | 2021.04.13 |
BOJ 16926 - ๋ฐฐ์ด ๋๋ฆฌ๊ธฐ 1 (0) | 2021.04.13 |
BOJ 15732 - ๋ํ ๋ฆฌ ์จ๊ธฐ๊ธฐ (0) | 2021.03.18 |
๐ฌ ๋๊ธ