본문 바로가기

코딩 테스트/그리디9

무지네 먹방 라이브 p.316 import heapq def solution(food_times, k): table=[] if sum(food_times) 2021. 1. 17.
볼링공 고르기 p.315 방법 1 N,M=map(int, input().split()) weight=list(map(int, input().split())) count=0 for i in range(N): for j in range(i,N): if weight[i]!=weight[j]: count+=1 print(count) 방법 2 N,M=map(int, input().split()) weight=list(map(int, input().split())) count=0 array=[0]*(M+1) for i in range(N): array[weight[i]]+=1 for j in range(1, M+1): N -= array[j] count += array[j]*N print(count) 2021. 1. 16.
만들 수 없는 금액 p.314 n=int(input()) money=list(map(int, input().split())) money.sort() target=1 for i in money: if target 2021. 1. 16.
문자열 뒤집기 이것이 취업을 위한 코딩테스트다. with 파이썬 p.313 n=input() count_1=0 count_0=0 if n[0]=='1': count_1+=1 else: count_0+=1 for i in range(len(n)-1): r=n[i] next_r=n[i+1] if r != next_r: if next_r=='1': count_1+=1 else: count_0+=1 result=min(count_0, count_1) print(result) 2021. 1. 16.
곱하기 혹은 더하기 이것이 취업을 위한 코딩테스트다. with 파이썬 p.312 방법1 n=input() result=int(n[0]) for i in range(1,len(n)): test_m=result*int(n[i]) test_p=result+int(n[i]) result=max(test_m,test_p) print(result) 방법 2 n=input() result=int(n[0]) for i in range(1,len(n)): num=int(n[i]) if num 2021. 1. 16.
모험가 길드 이것이 취업을 위한 코딩테스트이다. with 파이썬 p.311 n=int(input()) team=list(map(int, input().split())) team.sort() count=0 team_count=0 for i in team: count+=1 if count>=i: team_count+=1 count=0 print(team_count) 2021. 1. 16.