분류 전체보기
-
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
-
-
BaekJoon[1339]코딩/백준 그리디 문제 2023. 2. 17. 12:23
이문제는 간단하게 들어온 알파벳의 위치에따라 10을 곱해줘서 우선순위를 리스트에저장하고 ABB#A가 3째자리에있으니 10**(3-1)=100의 우선순위를부여 B는 두번째 첫번쨰자리에있으니 10**(2-1)+10**(1-1)=11 CS#마찬가지로 C=10**(2-1),S=10**(1-1) EX) ['A':100,'B':11,'C':10,'S':1]#정렬 이값에 FOR문을 리버스로 돌려서 9부터 1까지 삽입후 처음에 들어왔던 값들에 매치 시켜주면 끝 alphabet=[input() for i in range(int(input()))] alphabet_value={} priority=[] a=11 for i in alphabet: for j in range(len(i)): if alphabet_value.ge..
-
BaekJoon[16953]코딩/백준 그리디 문제 2023. 2. 17. 12:06
이문제의 핵심은 A를 B로 만드는것이아닌 B를 A로 만드는것이다. 단순히 B가 A가 되기위해서는 맨마지막 숫자1을 빼는게 가장 빠를것이다. 하지만 이는 B 의 맨마지막 숫자가 1일경우에만 가능한 일이고 2를 나누는 경우에는 2로 나우어떨어져야한다. 이는 반복문을 통해 B가A가 될때까지 이루어지고 만약 맨마지막 숫자가 1이 아니고 2로도 나누어 떨어지지 않는다면 이때 -1을 출력 또한 B가 A보다 작을때도 마찬지로 -1을 출력하면된다. import sys input=sys.stdin.readline def calculator(n,m,c): while m>=n: if m==n: print(c) return None if m%10==1: m//=10 elif m%2==0: m//=2 else: print(-1..