본문 바로가기

알고리즘7

[백준] 9017 크로스 컨트리 (풀지 못했던 이유 + 코드 + 해설) 구현 & 자료구조 https://www.acmicpc.net/problem/9017 9017번: 크로스 컨트리 입력 데이터는 표준입력을 사용한다. 입력은 T 개의 테스트 케이스로 주어진다. 입력 파일의 첫 번째 줄에 테스트 케이스의 수를 나타내는 정수 T 가 주어진다. 두 번째 줄부터는 두 줄에 하나의 www.acmicpc.net 코드 import sys input = sys.stdin.readline t = int(input()) for i in range(t): n = int(input()) team = list(map(int, input().strip().split())) manage = {} for j in range(n): if team[j] not in manage: # 팀 명수, 선수들 점수.. 2023. 7. 1.
[백준] 20365 블로그2 [풀지못했던 이유 + 코드] 그리디 & 구현 https://www.acmicpc.net/problem/20365 20365번: 블로그2 neighbor 블로그를 운영하는 일우는 매일 아침 풀고 싶은 문제를 미리 정해놓고 글을 올린다. 그리고 매일 밤 각각의 문제에 대하여, 해결한 경우 파란색, 해결하지 못한 경우 빨간색으로 칠한 www.acmicpc.net 코드 import sys from collections import Counter import copy input = sys.stdin.readline n = int(input()) col = list(map(str, input().strip())) dic = Counter(col) mainColor = [k for k ,v in dic.items() if max(dic.valu.. 2023. 6. 30.
[백준] 20300 서강근육맨 (해설 + 코드) 구현 https://www.acmicpc.net/problem/20300 20300번: 서강근육맨 PT 첫째 날에 $1$과 $4$를 선택하고, 둘째 날에 $2$와 $3$을 선택하고, 마지막 날에 $5$를 선택하면 $M$은 $5$가 되며, 이때가 $M$이 최소일 때이다. www.acmicpc.net 코드 import sys input = sys.stdin.readline n = int(input()) w = list(map(int, input().strip().split())) w.sort() cost = [] result = 0 if n % 2 == 1: for i in range(n//2): cost.append(w[i] + w[n-i-2]) result = max(*cost, w[len(w)-1]) .. 2023. 6. 29.