분류 전체보기 (460) 썸네일형 리스트형 #363 백준 파이썬 [18258] 큐 2 https://www.acmicpc.net/problem/18258 SOLUTION 큐를 구현할 때 리스트의 start 위치를 하나씩 바꾸어 가면서 하면 빠른 시간 내에 풀 수 있다. 큐의 가장 큰 문제는 리스트의 앞에서 자료를 뺄 때 O(n)의 시간이 걸린다는 점. 그러나 덱deque과 pypy로 풀리기에 pass하였다. PYTHON CODE from collections import deque import sys class fire: def __init__(self): self.queue = deque() def push(self, num): self.queue.append(num) def pop(self): if self.queue: return self.queue.popleft() else: re.. #362 백준 파이썬 [1004] 어린 왕자 https://www.acmicpc.net/problem/1004 PYTHON CODE T = int(input()) for _ in range(T): x1, y1, x2, y2 = map(int, input().split()) n = int(input()) planet = 0 #거치는 행성계 for _ in range(n): px, py, radius = map(int, input().split()) start = (((x1 - px) ** 2) + ((y1 - py) ** 2)) ** 0.5 #행성중심부터 시작점까지의 거리 end = (((px - x2) ** 2) + ((py - y2) ** 2)) ** 0.5 #행성중심부터 도착점까지의 거리 if start < radius and end < rad.. #361 백준 파이썬 [1735] 분수 합 https://www.acmicpc.net/problem/1735 PYTHON CODE def gcd(x,y): #최대공약수, 유클리드 호제 mod = x % y while mod >0: x = y y = mod mod = x % y return y A, B = map(int, input().split()) C, D = map(int, input().split()) N = gcd(A*D + C*B, B*D) print((A*D + C*B)//N, B*D//N) #360 백준 파이썬 [13300] 방 배정 https://www.acmicpc.net/problem/13300 PYTHON CODE import math N, K = map(int, input().split()) student = [[0] * 7 for _ in range(3)] #성별 / 학년별 for _ in range(N): S, Y = map(int, input().split()) student[S][Y] += 1 room = 0 for i in student: for j in i: room += math.ceil(j / K) print(room) #359 백준 파이썬 [2605] 줄 세우기 https://www.acmicpc.net/problem/2605 PYTHON CODE from collections import deque #회전큐로 구현 N = int(input()) student = list(map(int, input().split())) result = deque() for std, move in enumerate(student): result.rotate(move) #오른쪽으로 돌림 result.append(std + 1) #사람 추가 result.rotate(-move) #왼쪽으로 원상복구 print(*result) #358 백준 파이썬 [2669] 직사각형 네개의 합집합의 면적 구하기 https://www.acmicpc.net/problem/2669 PYTHON CODE paper = [[0 for _ in range(101)] for _ in range(101)] for _ in range(4): x1, y1, x2, y2 = map(int, input().split()) #사각형 부분만 1로 바꾸어줌 for i in range(x1, x2): for j in range(y1, y2): paper[i][j] = 1 answer = 0 for row in paper: answer += sum(row) print(answer) #357 백준 파이썬 [10026] 적록색약 - BFS https://www.acmicpc.net/problem/10026 SOLUTION BFS(너비우선탐색 그래프)를 통해 쉽게 해결 가능하다. (참조: https://claude-u.tistory.com/211) BFS를 기본인 상태에서 한 번, G를 R로 바꾼 상태에서 한 번 실행시켜준다. PYTHON CODE from collections import deque #큐를 빨리 돌리기위함 #BFS함수 정의 def bfs(i, j): queue = deque() queue.append([i, j]) color = grid[i][j] #하나의 컬러만 while queue: [i, j] = queue.popleft() visited[i][j] = True if i + 1 < N and [i+1, j] not i.. #356 백준 파이썬 [10815] 숫자 카드 https://www.acmicpc.net/problem/10815 SOLUTION 분류되어 있는 이분탐색도 좋지만 dict 파일 안에 숫자를 더하여 key를 기반으로 찾는 방법을 선택했다. M의 숫자가 더 크다면 dict 또한 이분 탐색으로 하는 게 더 편하겠지만 충분히 풀 수 있음으로 사용하지 않았다. PYTHON CODE N = int(input()) N_list = list(map(int, input().split())) M = int(input()) M_list = list(map(int, input().split())) N_count = {} for n in N_list: N_count[n] = True for m in M_list: if m in N_count: print(1, end = '.. 이전 1 ··· 4 5 6 7 8 9 10 ··· 58 다음 목록 더보기