
SWEA 1251 하나로 (파이썬)
2022. 9. 30. 15:13
SWEA
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV15StKqAQkCFAYD SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 풀이 import math def find_set(x): while x != p[x]: x = p[x] return x for tc in range(int(input())): N = int(input()) info = [[0, 0] for _ in range(N+1)] r_info = list(map(int, input().split())) c_info = list(map(int, input().s..

백준 1941 소문난 칠공주 (파이썬)
2022. 9. 30. 13:37
백준
풀이 및 해설(주석) import sys # sys.stdin = open('칠공주.txt', 'r') sys.setrecursionlimit(10**6) # dfs와 bfs가 섞여서 사용됨 def solve(nums, S, Y): global rst, visit if Y > 3: return # 중복 방지를 위해 7개의 글자의 좌표를 정렬해서 튜플로 묶어서 visit이란 set에 저장 if len(nums) == 7: nums = tuple(sorted(nums)) if nums not in visit: rst += 1 visit.add(nums) return return # 여기서 부터가 bfs섞인 부분, nums에 넣어준 좌표들을 pop하면 안됨 그냥 읽으면 됨 for num in nums: r, ..

SWEA 1249 보급로 (파이썬)
2022. 9. 30. 11:53
SWEA
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV15QRX6APsCFAYD SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 풀이 (다익스트라) from heapq import heappop, heappush for tc in range(1, int(input())+1): N = int(input()) maps = [list(map(int, input())) for _ in range(N)] # 다익스트라로 최단 거리 구하기 visit = [[0]*N for _ in range(N)] D = [[0xffffff]*N fo..

SWEA 5250 최소비용 bfs (파이썬)
2022. 9. 29. 17:22
SWEA
https://swexpertacademy.com/main/learn/course/lectureProblemViewer.do SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 풀이 및 해설(주석) from collections import deque def bfs(r, c): # 0, 0의 visited의 값은 0으로 초기화 visited[r][c] = 0 Q = deque() Q.append((r, c)) while Q: r, c = Q.popleft() for dr, dc in [[1, 0], [0, 1], [-1, 0], [0, -1]]: nr, nc = r + dr, c + dc if 0

SWEA 5249 최소 신장 트리 Prim (파이썬)
2022. 9. 29. 15:11
SWEA
https://swexpertacademy.com/main/learn/course/lectureProblemViewer.do SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 풀이 및 해설(주석) def prim(r, V): MST = [0] * (V+1) # 정점 포함 여부 key = [1e9] * (V+1) # 가중치의 최대값 이상으로 초기화, key[v]는 v가 MST에 속한 정점과 연결될 때의 가중치 key[r] = 0 # 시작 정점의 key 0으로 초기화 for _ in range(V): # V+1개의 정점 중 V개 선택 u, w = 0, 1e9 # MST에 포함되지 않은 정점 중, key가 최소인 u ..

SWEA 5249 최소 신장 트리 Kruskal (파이썬)
2022. 9. 29. 14:59
SWEA
https://swexpertacademy.com/main/learn/course/lectureProblemViewer.do SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 풀이 및 해설(주석) def find_set(x): while x != p[x]: # 루트인지 아닌지 x = p[x] return x for tc in range(int(input())): N, E = map(int, input().split()) # 간선들의 리스트 저장 [[u, v, weight], ...] edges = [list(map(int, input().split())) for _ in range(E)] # kruskal 알고리..

SWEA 5248 그룹 나누기 (파이썬)
2022. 9. 29. 12:50
SWEA
https://swexpertacademy.com/main/learn/course/lectureProblemViewer.do SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 풀이 def find_set(x): val = P[x] if x == val: return x else: return find_set(P[x]) def union(x, y): P[find_set(x)] = P[find_set(y)] for tc in range(int(input())): N, M = map(int, input().split()) info = list(map(int, input().split())) P = [i for i in..

백준 1697 숨바꼭질 (파이썬)
2022. 9. 28. 21:19
백준
아이디어 바로 전에 올렸던 swea의 연산 문제와 완전 똑같다. https://ryuwc.tistory.com/112 SWEA 5247 연산 (그래프) (파이썬) https://swexpertacademy.com/main/learn/course/lectureProblemViewer.do SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 풀이 및 해설(주석).. ryuwc.tistory.com 위의 문제를 참고해주세요 풀이 및 해설(주석) from collections import deque def solve(num): global rst Q = deque() # Q에 현재 숫자와 움직임의 숫자를 넣어준다. 현재는..