반응형 백준39 [백준/Python] 1005번 ACM Craft 문제https://www.acmicpc.net/problem/1005풀이import sysfrom collections import dequeinput = sys.stdin.readlinedef solve(): n, k = map(int, input().split()) D = list(map(int,input().split())) g = {} memo = [0] * n answerlist = [0] * n for i in range(k): x, y = map(int, input().split()) x -= 1 y -= 1 if x not in g: g[x] = [] g[x].append(y).. 2025. 3. 18. [백준/Python] 1647번 도시 분활 계획 문제https://www.acmicpc.net/problem/1647풀이import heapqimport sysinput = sys.stdin.readlinedef prim(graph, start): mst = [] visited = set() min_heap = [(0, start, None)] total_weight = 0 while min_heap: weight, current, previous = heapq.heappop(min_heap) if current in visited: continue visited.add(current) total.. 2025. 3. 2. [백준/Python] 11758번 CCW 문제https://www.acmicpc.net/problem/11758 소스코드p1 = list(map(int, input().split()))p2 = list(map(int, input().split()))p3 = list(map(int, input().split()))def ccw(p1, p2, p3): return ((p2[0] - p1[0]) * (p3[1] - p2[1])) - ((p3[0] - p2[0]) * (p2[1] - p1[1]))result = ccw(p1, p2, p3)if result > 0: print(1)elif result ccw를 세 점이 이루는 방향을 판단하는 데 사용합니다. 점 a, b, c가 있을때 a -> b -> c의 ccw 알고리즘 결과가 양수라면 반.. 2025. 1. 2. [백준/Python] 1717번 집합의 표현 - (유니온파인드) 문제https://www.acmicpc.net/problem/1717 소스코드import sys input = sys.stdin.readlinesys.setrecursionlimit(10 ** 6)n, m =map(int, input().split())parent = [i for i in range(n + 1)]def union(a, b): a = find(a) b = find(b) if a b: parent[a] = bdef find(a): if a == parent[a]: return a parent[a] = find(parent[a]) return parent[a]def is_connected(a, b): return find(a) =.. 2024. 11. 26. [백준/Python] 11404번 플로이드 문제https://www.acmicpc.net/problem/11404 소스코드import sysinput = sys.stdin.readlinen = int(input())m = int(input())graph = [[1e11 for _ in range(n + 1)] for _ in range(n + 1)]for i in range(n): graph[i + 1][i + 1] = 0for i in range(m): a, b, c = map(int, input().split()) graph[a][b] = min(graph[a][b], c)for k in range(1, n + 1): for i in range(1, n + 1): for j in range(1, n + 1):.. 2024. 11. 25. [백준/Python] 2252번 줄 세우기 - (위상 정렬) 문제https://www.acmicpc.net/submit/2252/86061561 소스코드import sys from collections import dequeinput = sys.stdin.readlinen, m = map(int, input().split())indegree = [0] * ngrape = {}for i in range(m): a, b = map(int, input().split()) if a - 1 not in grape: grape[a - 1] = [] grape[a - 1].append(b - 1) indegree[b - 1] += 1queue = deque()for i in range(n): if indegree[i] == 0: .. 2024. 11. 24. [백준/Python] 1516번 게임 개발 - (위상정렬) 문제https://www.acmicpc.net/problem/1516 소스코드import sys from collections import dequeinput = sys.stdin.readlinequeue = deque()n = int(input())grape = {}indegree = [0] * nanswer = [0] * ntime = [0] * nfor i in range(n): data = list(map(int, input().split())) data_len = len(data) - 1 time[i] = data[0] indegree[i] = data_len - 1 if data_len - 1 == 0: queue.append(i) for j in .. 2024. 11. 22. [백준 / Python] 2166번 다각형의 면적 문제 https://www.acmicpc.net/problem/2166 코드 import sysinput = sys.stdin.readlinen = int(input())data = []for i in range(n): data.append(list(map(int, input().split())))data.append(data[0])answer = 0.0for i in range(n): answer += (data[i][0]*data[i+1][1] - data[i+1][0]*data[i][1]) answer = abs(answer / 2.0)print(round(answer,1)) https://ko.wikipedia.org/wiki/%EC%8B%A0%EB%B0%9C%EB%81%88_%E.. 2024. 10. 27. [백준 / Python] 1312번 소수 문제https://www.acmicpc.net/problem/1312 소스코드a , b, n = map(int, input().split())c = a // ba = a % b for i in range(1000003): a *= 10 if n == i + 1: print(a // b) break a = a % b 직접 나눗셈을 하는 문제입니다. 바로 a / b해서 소수점을 구하려고하면 소수 길이 제한이 있어, 1,000,000번째 소수점 자리수에 도달하지 못합니다. 넉넉하게 1000003으로 두고 풀었습니다. 2024. 10. 15. [백준/Python] 1747번 소수&팰린드롬 문제https://www.acmicpc.net/problem/1747소스코드def primeCheck(data): if data == 1: return False for i in range(2, int(data ** 0.5) + 1): if data % i == 0: return False return Truedef palindromeCheck(data): data = str(data) if data == data[::-1]: return True else: return False n = int(input())while True: if primeCheck(n) and palindrome.. 2024. 10. 4. 이전 1 2 3 4 다음 728x90 반응형