본문 바로가기

Algorithm/BOJ133

[백준] 1700번 - 멀티탭 스케줄링 (파이썬) # 멀티탭 스케줄링 from asyncore import close_all import sys input = sys.stdin.readline N, K = map(int, input().split()) use = list(map(int, input().split())) plugs = [] result = 0 for i in range(K): # 이미 있다면 if use[i] in plugs: continue # 빈공간이 있다면 if len(plugs) != N: plugs.append(use[i]) continue # 가장 멀리 있는 플러그의 인덱스 far_one = 0 temp = 0 # 현재 꽂혀있는 플러그들 확인 for plug in plugs: # 앞으로 사용할 플러그에 없으면 if plug no.. 2022. 2. 12.
[백준] 2887번 - 행성 터널 (파이썬) # 행성 터널 import copy import heapq import sys input = sys.stdin.readline N = int(input()) planets = [] for i in range(N): x, y, z = map(int, input().split()) planets.append((x, y, z, i)) planets_x = copy.deepcopy(planets) planets_y = copy.deepcopy(planets) planets_z = copy.deepcopy(planets) planets_x.sort(key=lambda index: index[0]) planets_y.sort(key=lambda index: index[1]) planets_z.sort(key=lam.. 2022. 2. 12.
[백준] 13460번 - 구슬 탈출 2 (파이썬) # 구슬 탈출 2 from collections import deque import sys input = sys.stdin.readline # . # 0 R B => 빈칸, 장애물, 구멍, 빨간구슬, 파란구슬 N, M = map(int, input().split()) arr = [] red_x, red_y = 0, 0 blue_x, blue_y = 0, 0 for i in range(N): arr.append(list(input().strip())) for j in range(len(arr[i])): if arr[i][j] == 'R': red_x, red_y = i, j arr[i][j] = '.' elif arr[i][j] == 'B': blue_x, blue_y = i, j arr[i][j] = '.. 2022. 2. 11.
[백준] 13459번 - 구슬 탈출 (파이썬) # 구슬 탈출 from collections import deque import sys input = sys.stdin.readline # . # 0 R B => 빈칸, 장애물, 구멍, 빨간구슬, 파란구슬 N, M = map(int, input().split()) arr = [] red_x, red_y = 0, 0 blue_x, blue_y = 0, 0 for i in range(N): arr.append(list(input().strip())) for j in range(len(arr[i])): if arr[i][j] == 'R': red_x, red_y = i, j arr[i][j] = '.' elif arr[i][j] == 'B': blue_x, blue_y = i, j arr[i][j] = '.'.. 2022. 2. 11.
[백준] 17143번 - 낚시왕 (파이썬) # 낚시왕 import copy import sys input = sys.stdin.readline N, M, S = map(int, input().split()) arr = [[0] * (M+1) for _ in range(N+1)] for _ in range(S): n, m, speed, direction, big = map(int, input().split()) arr[n][m] = (speed, direction, big) shark_move = [[], [-1, 0], [1, 0], [0, 1], [0, -1]] def fishing(now): global result for i in range(1, N+1): if arr[i][now] != 0: result += arr[i][now][2] a.. 2022. 2. 11.
[백준] 1043번 - 거짓말 (파이썬) # 거짓말 import sys input = sys.stdin.readline N, M = map(int, input().split()) know = set(map(int, input().split()[1:])) party = [] for _ in range(M): people = set(map(int, input().split()[1:])) party.append(people) can = [True] * M for _ in range(M): for i, people in enumerate(party): if people & know: can[i] = False know = know | people result = 0 for i in range(M): if can[i]: result += 1 print(.. 2022. 2. 9.
[백준] 1865번 - 웜홀 (파이썬) # 웜홀 import sys input = sys.stdin.readline MAX = sys.maxsize def bf(): for k in range(1, N+1): for i in range(1, N+1): for time, city in arr[i]: if times[city] > time + times[i]: times[city] = time + times[i] if k == N: return True return False T = int(input()) for _ in range(T): N, M, W = map(int, input().split()) arr = [[]for _ in range(N+1)] for _ in range(M): a, b, time = map(int, input().sp.. 2022. 2. 9.