문제
https://www.acmicpc.net/problem/2309]
2309번: 일곱 난쟁이
아홉 개의 줄에 걸쳐 난쟁이들의 키가 주어진다. 주어지는 키는 100을 넘지 않는 자연수이며, 아홉 난쟁이의 키는 모두 다르며, 가능한 정답이 여러 가지인 경우에는 아무거나 출력한다.
www.acmicpc.net
Algorithm
입력으로 받은 값들을 중 두 개의 값을 뽑을 떄 그 두 개의 합을 입력값의 총합에서 뺏을 때 100이 되는 값들을 찾고 전체 값에서 그 두개의 값을 제거한다.
Code
from collections import deque
from itertools import combinations as cb
input = __import__('sys').stdin.readline
heights = deque()
s = 0
for i in range(9):
h = int(input())
heights.append(h)
s += h
no = []
fine = deque()
for (i, j) in cb(heights, 2):
if s - (i + j) == 100:
no = [i, j]
while True:
if len(heights) == 7:
break
h = heights.popleft()
if h not in no:
heights.append(h)
for h in sorted(heights):
print(h)
'Koala - 9기 > 기초 알고리즘 스터디' 카테고리의 다른 글
[백준/Python] 1718번 (0) | 2023.02.12 |
---|---|
[백준/C++] 11655번 ROT13 (0) | 2023.02.12 |
[백준 / C++] 10825번: 국영수 (0) | 2023.02.12 |
[백준/Python] 15650번 N과 M (2) (0) | 2023.02.12 |
[백준 / python] #12789: 도키도키 간식드리미 (0) | 2023.02.12 |