본문 바로가기

전체 글293

[Ch.3 - 그리디] 1이 될 때까지 My code n,k = map(int,input().split()) count = 0 while n!=1: if n%k==0: n = n/k count += 1 else: n -= 1 count += 1 print(count) Answer 1 n,k = map(int,input().split()) result = 0 while n >= k: while n % k != 0: n -= 1 result += 1 n //= k result += 1 while n > 1: n -= 1 result += 1 print(result) Answer 2 n,k = map(int,input().split()) result = 0 while True: target = (n // k) * k result += (n - ta.. 2022. 1. 28.
[Ch.3 - 그리디] 숫자 카드 게임 My code n,m = map(int,input().split()) maxval = 0 for i in range(n): a = list(map(int,input().split())) minval = min(a) maxval = max(minval, maxval) print(maxval) Answer 1 n,m = map(int,input().split()) result = 0 for i in range(n): data = list(map(int,input().split())) min_value = min(data) result = max(result, min_value) print(result) Answer 2 n,m = map(int,input().split()) result = 0 for i in.. 2022. 1. 28.
[Ch.3 - 그리디] 큰 수의 법칙 My code n,m,k = map(int,input().split()) a = list(map(int,input().split())) a.sort() a1 = a[n-1] #첫 번째로 큰 수 a2 = a[n-2] #두 번째로 큰 수 sum = 0 count = 0 while True: for i in range(k): if count==m: break sum += a1 count += 1 if count==m: break sum += a2 count += 1 print(sum) Answer 1 n,m,k = map(int,input().split()) data = list(map(int,input().split())) data.sort() first = data[n-1] second = data[n-2.. 2022. 1. 28.
[코드업 Python 기초 100제] - 6098. 성실한 개미 문제 설명 영일이는 생명과학에 관심이 생겨 왕개미를 연구하고 있었다. 왕개미를 유심히 살펴보던 중 특별히 성실해 보이는 개미가 있었는데, 그 개미는 개미굴에서 나와 먹이까지 가장 빠른 길로 이동하는 것이었다. 개미는 오른쪽으로 움직이다가 벽을 만나면 아래쪽으로 움직여 가장 빠른 길로 움직였다. (오른쪽에 길이 나타나면 다시 오른쪽으로 움직인다.) 이에 호기심이 생긴 영일이는 그 개미를 미로 상자에 넣고 살펴보기 시작하였다. 미로 상자에 넣은 개미는 먹이를 찾았거나, 더 이상 움직일 수 없을 때까지 오른쪽 또는 아래쪽으로만 움직였다. 미로 상자의 구조가 0(갈 수 있는 곳), 1(벽 또는 장애물)로 주어지고, 먹이가 2로 주어질 때, 성실한 개미의 이동 경로를 예상해보자. 단, 맨 아래의 가장 오른쪽에 도.. 2022. 1. 26.