N개의 10진수 정수가 주어진다. 플레이어에게 정수를 그냥 정렬하는 것은 너무 쉽기 때문에, 아래 기준에 따라 정수를 정렬하기로 한다.
플레이어가 정수를 잘 정렬했을 때, 앞에서 K번째에 위치한 수는 어떤 수가 될지 구해보자.
첫째 줄에 주어지는 정수의 수 N과 플레이어가 찾으려는 정수의 위치 K가 공백을 두고 주어진다.
둘째 줄에 정수 , , ... , 이 공백을 두고 주어진다.
def binary_1count(x):
return bin(x)[2:].count('1')
input1 = input()
input2 = input()
k = int(input1.split()[1])
list1 = list(map(int, input2.split()))
list1.sort(reverse=True, key=lambda x:(binary_1count(x), x))
print(list1[k-1])
정렬 기준이 2가지(이진수에 들어있는 1의 개수 10진수)로 복잡해서 결국 다른 풀이를 참고했다.
https://level.goorm.io/
https://dong8ee.tistory.com/m/80
https://mola2.tistory.com/2
https://art-coding3.tistory.com/6
https://brownbears.tistory.com/467
https://korbillgates.tistory.com/171
https://infinitt.tistory.com/122
https://docs.python.org/3/howto/sorting.html