Notice
Recent Posts
Recent Comments
Link
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- Merge sort
- 지도학습
- 자바
- bineary search
- 파이썬 오류
- 멱등
- BOJ
- 코딩테스트
- 알고리즘
- 스택과 힙
- 오버라이딩
- HTTP
- 이진탐색
- 프로그래머스
- 딕셔너리
- 강화학습
- 너비우선탐색
- 파이썬
- 머신러닝
- 딥러닝
- 캐싱
- 해시
- 파이썬 알고리즘
- 깊이우선탐색
- 코테
- 비지도학습
- rest api
- 코딩
- post
- 백준
Archives
- Today
- Total
chae._.chae
[Algorithm] 백준 #9017 크로스 컨트리 본문
728x90
반응형
https://www.acmicpc.net/problem/9017
import sys
from collections import defaultdict
input = sys.stdin.readline
T = int(input())
while T:
# 각 팀당 선수 몇명인지 계산후, 여섯보다 작으면 모두 삭제
N = int(input())
players = list(map(int, input().split()))
team_count = defaultdict(int) # 선수 카운트
team_dict = defaultdict(list)
for i in players:
team_count[i] += 1
# print(team_count) # {1: 6, 2: 2, 3: 6, 4: 1}
# 제거할 팀
teams_to_remove = [key for key, value in team_count.items() if value < 6]
players = [player for player in players if player not in teams_to_remove]
for key in teams_to_remove:
del team_count[key]
# 팀별로 점수 저장
for index, player in enumerate(players):
team_dict[player].append(index+1)
# 각 팀별 상위 4명 점수 계산 & 다섯번째 선수 점수 기록
team_scores={}
fifth_scores = {}
for team, scores in team_dict.items():
scores.sort()
team_scores[team] = sum(scores[:4])
fifth_scores[team] = scores[4]
# print(team_scores) # {1: 18, 3: 18}
min_score = float('inf') # 양의 무한대
min_team = None
for team, score in team_scores.items():
if score < min_score or (score == min_score and fifth_scores[team] < fifth_scores[min_team]):
min_score = score
min_team = team
print(min_team)
# print(players) # [1, 3, 3, 1, 3, 1, 1, 3, 1, 3, 3, 1]
T -= 1
- 각 팀당 선수가 몇명인지 계산하고 6명보다 작으면 모두 삭제
- team_dict에 팀별로 점수를 저장. key:팀, value:점수리스트
- 팀별 상위 4명 점수 계산 & 다섯번째 선수의 점수 기록
📌 다시 봐야 할 부분
일단.. 천천히 구현해나가면 할수있음
- 딕서너리에 value값으로 리스트 넣고싶음 defaultdict(list) 이렇게 작성 가능하다
- enumerate( ): 리스트의 원소에 순서값을 부여해주는 함수. 인덱스와 원소에 동시 접근 방법
- min_score = float('inf') # 양의 무한대 설정
728x90
'파이썬 알고리즘 > BOJ' 카테고리의 다른 글
[Algorithm] 백준 #13305 주유소 (0) | 2024.07.08 |
---|---|
[Algorithm] 백준 #17266 어두운 굴다리 (0) | 2024.07.08 |
[Algorithm] 백준 #1244 스위치 켜고 끄기 (0) | 2024.07.07 |
[Algorithm] 백준 #1205 등수 구하기 (0) | 2024.07.07 |
[Algorithm] 백준 #20125 쿠키의 신체 측정 (0) | 2024.07.07 |