Python_알고리즘/Gold V
-
14891. [Python]톱니바퀴Python_알고리즘/Gold V 2024. 8. 7. 21:24
1. 문제 https://www.acmicpc.net/problem/14891 2. 접근 방법 시간 제한: 2초메모리 제한: 512MB구현시뮬레이션 3. 파이썬 코드 import sysfrom collections import deque# 시계 방향 회전def right(target): check = matrix[target].pop() matrix[target].appendleft(check)# 반시계 방향 회전def left(target): check = matrix[target].popleft() matrix[target].append(check)# 연결된 톱니바퀴 체크def DFS(start,dir): # 방문처리를 통해 연결된 톱니바퀴 회전 visited = [..
-
2589. [Python]보물섬Python_알고리즘/Gold V 2024. 8. 6. 18:22
1. 문제 https://www.acmicpc.net/problem/2589 2. 접근 방법 시간 제한: 1초메모리 제한: 512MB너비 우선 탐색 3. 파이썬 코드 from collections import dequeimport sysinput = sys.stdin.readline# 방향 탐색direction = [(0,-1), (-1,0), (0,1), (1,0)]# 너비 우선 탐색def BFS(x,y): global max_value visited = [ [0] * M for _ in range(N) ] visited[x][y] = 1 queue = deque([(x,y)]) while queue: check = queue.popleft() fo..
-
2470. [Python]두 용액Python_알고리즘/Gold V 2024. 7. 29. 17:46
1. 문제 https://www.acmicpc.net/problem/2470 2. 접근 방법 시간 제한: 1초메모리 제한: 128MB투 포인터 3. 파이썬 코드 2025-01-18 일에 다시 푼 코드N = int(input())num_list = list(map(int,input().split()))num_list.sort()left = 0right = N - 1target = 10**9answer = []if num_list[0] >= 0: answer = [num_list[0], num_list[1]]elif num_list[-1] = 0: right -= 1 else: left += 1print(*answer)5달 전에 푼 코드N = int(..
-
2212. [Python]센서Python_알고리즘/Gold V 2024. 7. 12. 07:57
1. 문제 https://www.acmicpc.net/problem/2212 2. 접근 방법 시간 제한: 2초메모리 제한: 128MB그리디 알고리즘 3. 파이썬 코드 N = int(input())K = int(input())num_list = list(map(int,input().split()))# 집중국의 개수가 더 많으면 그냥 다 놓기때문에 0 처리if K >= N: print(0)# 외의 경우else: # 중복된 개수를 체크하는 변수 cnt = 0 # 기지국 정렬 num_list.sort() # 기지국들 거리를 체크할 리스트 answer_list = [] # 기지국 반복문 진행 for i in range(1,N): # 앞뒤값을 비교하므로 ..
-
2660. [Python]회장뽑기Python_알고리즘/Gold V 2024. 7. 3. 13:02
1. 문제 https://www.acmicpc.net/problem/2660 2. 접근 방법 시간 제한: 1초메모리 제한: 128MB너비우선탐색 3. 파이썬 코드 from collections import dequeimport sysinput = sys.stdin.readline# 너비 우선 탐색 진행def BFS(start): queue = deque([start]) # 친구의 점수를 리턴해줄 변수 max_value = 0 # 처음 시작점 0 으로 선언 distance[start] = 0 # queue가 존재할때 까지 반복 while queue: check = queue.popleft() for i in graph[check]: ..
-
23978. [Python]급상승Python_알고리즘/Gold V 2024. 7. 1. 16:59
1. 문제 https://www.acmicpc.net/problem/23978 2. 접근 방법 시간 제한: 1초메모리 제한: 512MB이분 탐색 3. 파이썬 코드 N, K = map(int,input().split())days = list(map(int,input().split()))# 시작 값start = 1# 끝 값 구하고자 하는 돈end = K# 이분 탐색while start = K: end = cost - 1 # 작은 경우 start 값을 높여 값을 높임 else: start = cost + 1print(start) 4. 문제를 풀고난 후 생각 문제를 읽고 숫자의 범위가 너무 커서 이분 탐색 방법을 고민했고 어떤 값을 가지고 이분탐색을 진행할지 생각을 많이했던 ..
-
10026. [Python]적록색약Python_알고리즘/Gold V 2024. 6. 28. 12:51
1. 문제 https://www.acmicpc.net/problem/10026 2. 접근 방법 시간 제한: 1초메모리 제한: 128MB깊이 우선 탐색 3. 파이썬 코드 def DFS(start, flag): # DFS 진행 global count stack = [start] # 초기값 선언 visited[start[0]][start[1]] = True while stack: y,x = stack.pop() # 방향 배열 탐색 for k in range(4): ny = y + direction[k][0] nx = x + direction[k][1] # 범위내 존재 시 ..
-
5972. [Python]택배 배송Python_알고리즘/Gold V 2024. 6. 20. 18:50
1. 문제 https://www.acmicpc.net/problem/5972 2. 접근 방법 시간 제한: 1초메모리 제한: 128MB다익스트라 3. 파이썬 코드 import sysimport heapq# 다익스트라 알고리즘def dijkstra(start): # 항상 초기 거리 0 선언 및 시작 위치!!! 중요 distance[start] = 0 queue = [(0,1)] # 우선순위 큐를 통해서 구현 while queue: # 현재 비용과 노드 pop cost, now = heapq.heappop(queue) # 현재 거리에 cost 값과 노드에 cost 값이 더 큰 경우 반복문 마저 진행 if cost > distance..
-
9251. [Python]LCSPython_알고리즘/Gold V 2024. 6. 16. 15:14
1. 문제 https://www.acmicpc.net/problem/9251 2. 접근 방법 시간 제한: 0.1초메모리 제한: 256MB다이나믹 프로그래밍 3. 파이썬 코드 from pprint import pprint as printword_one = input()word_two = input()# 처음 단어의 길이one_length = len(word_one)# 두번째 단어의 길이two_length = len(word_two)# LCS 적용할 리스트LCS_matrix = [ [0]*(one_length+1) for _ in range(two_length+1)]# 최대값 체크할 변수max_value = 0# 처음단어 반복문for i in range(one_length+1): # 두번째 단어 반복..
-
12865. [Python]평범한 배낭Python_알고리즘/Gold V 2024. 6. 5. 01:27
1. 문제 https://www.acmicpc.net/problem/12865 2. 접근 방법 시간 제한: 2초메모리 제한: 512MBDP(다이나믹 프로그래밍) 3. 파이썬 코드 import sysinput = sys.stdin.readlineN, K = map(int,input().split())# 가방bag = []# weight, value 값 가방에 저장for _ in range(N): weight, value = map(int,input().split()) bag.append((weight,value))# dp 값을 K(무게) +1 만큼 생성dp = [0] * 100001# N개의 물건 개수만큼 반복for i in range(N): # weight, value 값 분해 w..