코딩
-
BaekJoon[1462]코딩/백준 그리디 문제 2023. 2. 18. 23:16
import sys input=sys.stdin.readline _,M=map(int,input().split()) L=sorted(list(map(int,input().split()))) Plus=[] Minus=[] target=[] for i in L: if i 0: target.append(Minus[(len(Minus) // M) * M]) for i in range(0, len(Plus) // M): target.append(Plus[i * M]) if len(Plus) % M > 0: target.append(Plus[(len(Plus) // M) * M]) target=sorted(target) print(sum(2*target[:-1])+target[-1])
-
BaekJoon[1213]코딩/백준 그리디 문제 2023. 2. 17. 20:58
for-else=> for문이 break등에 걸리지 않고 끝까지 수행되었을 때 else를 수행 N = sorted(input()) M={} for alpha in N: M.setdefault(alpha,0) M[alpha]+=1 ans,center='','' for alphabet,amount in M.items(): if amount%2: if center!='': print("I'm Sorry Hansoo") break center = alphabet ans+=alphabet*(amount//2) else: print(ans+center+ans[::-1])
-
BaekJoon[2437]코딩/백준 그리디 문제 2023. 2. 17. 16:45
https://aerocode.net/392#%EA%B0%9C%EC%9A%94 참고한곳 백준 2437 풀이 및 해설 개요 매우 복잡해보이는 문제가 그림으로 풀면 매우 단순하게 풀리는 경우는 그리 드문일이 아닙니다. 이 문제는 수학적 귀납법으로도 풀 수 있지만, 수직선을 사용하면 훨씬 직관적이고 쉽게 aerocode.net 핵심은 측정할수있는 무게의 구간이 이어지게 만드는것이다. 오늘 배운것:문제가 복잡하면 그림을 그려보자.. import sys input=sys.stdin.readline N=int(input()) L=sorted(list(map(int,input().split()))) T=1 for arr in L: if T
-