목록Python (288)
홍우진의 개발새발
문제 링크https://www.acmicpc.net/problem/17266풀이 코드import sysinput = sys.stdin.readlinen = int(input())m = int(input())locations = list(map(int, input().split()))height = 0height = locations[0]height = max(height, n - locations[-1])for i in range(1, m): distance = locations[i] - locations[i-1] height = max(height, (distance + 1) // 2)print(height)코드 해석 1. 굴다리 시작 지점 ~ 첫 번째 가로등2. 마지막 가로등 ~ 굴다리 끝..
문제 링크https://www.acmicpc.net/problem/28279풀이 코드import sysfrom collections import dequedq = deque()for _ in range(int(sys.stdin.readline())): command = sys.stdin.readline().split() cmd = int(command[0]) if cmd == 1: dq.appendleft(int(command[1])) elif cmd == 2: dq.append(int(command[1])) elif cmd == 3: if dq: print(dq.popleft()) else: ..
문제 링크https://www.acmicpc.net/problem/4158풀이 코드import sysinput = sys.stdin.readlinewhile True: n, m = map(int, input().split()) if n == 0 and m == 0: break sg_cd = [int(input()) for _ in range(n)] # 상근이, 선영이의 CD 목록 입력 sy_cd = [int(input()) for _ in range(m)] sg_p = sy_p = cnt = 0 while sg_p 코드 해석투포인터 알고리즘을 사용한다.각 배열을 가리키는 포인터를 하나씩 두고두 포인터가 가리키는 값을 비교하며 ..
문제 링크https://www.acmicpc.net/problem/2343풀이 코드n, m = map(int, input().split())gang = list(map(int, input().split()))left, right = max(gang), sum(gang) dap = 0while left 코드 해석이분탐색을 활용한다.left, right, mid 값을 어떻게 설정해야할지 고민이 많았는데길이 제한으로 한 뒤 카운팅하면 될 것 같았다. 체감 난이도: ★★★☆☆많이 헤멨다..
문제 링크https://www.acmicpc.net/problem/2512풀이 코드n = int(input())jibang = list(map(int,input().split()))m = int(input())start = 1end = max(jibang)dap = 0while start 코드 해석그냥 구해도 될 것 같지만 수가 커지면 엄청 오래 걸린다.이분 탐색 방법을 사용한다. 체감 난이도: ★☆☆☆☆
문제 링크https://www.acmicpc.net/problem/1072풀이 코드x, y = map(int,input().split())z = y * 100 // x left, right = 1, 1000000000dap = -1while left z: dap = mid right = mid - 1 else: left = mid + 1print(dap)코드 해석이분탐색으로 풀었다.탐색 범위를 반으로 나눠서 탐색하는것이다.000100000000 원래 수열000100 000000 반 나누고 왼쪽 선택000 100 반 나누고 오른쪽 선택10 0 반 나누고 왼쪽 선택 1 0 반 나누고 왼쪽 선택1이렇게 찾으면 시간 절약이 훨씬 많이 된다. 체감 난이도: ★★☆☆☆
문제 링크https://www.acmicpc.net/problem/1449풀이 코드m, l = map(int,input().split())wat = list(map(int,input().split()))cnt = 0tape_end = 0wat.sort()for i in wat: if i >= tape_end: cnt += 1 tape_end = i + lprint(cnt)코드 해석그리디 알고리즘을 사용했다.물 새는곳을 오름차순 정렬을 한 후if문에서 제일 처음 테이프를 붙이며 테이프의 끝나는 길이를 지정한다.끝나는 길이를 기반으로 for문을 돌며 비교하고만약 길이를 넘어서면 새 테이프를 사용한다. 체감 난이도: ★☆☆☆☆
문제 링크https://www.acmicpc.net/problem/2847풀이 코드dan = []for _ in range(int(input())): dan.append(int(input()))cnt = 0for i in range(len(dan)-1,0,-1): while dan[i] 코드 해석그리디 알고리즘을 사용했다.간단한 구현이다. 체감 난이도: ☆☆☆☆☆