728x90
๋ฐ˜์‘ํ˜•

๋ฐฑ์ค€ DFS 3

[๋ฐฑ์ค€ 1012] [dfs/bfs] ์œ ๊ธฐ๋† ๋ฐฐ์ถ”

๐Ÿ’ป ๋ฐฑ์ค€ 1012๋ฒˆ [์œ ๊ธฐ๋† ๋ฐฐ์ถ”] 1012๋ฒˆ: ์œ ๊ธฐ๋† ๋ฐฐ์ถ” ์ฐจ์„ธ๋Œ€ ์˜๋†์ธ ํ•œ๋‚˜๋Š” ๊ฐ•์›๋„ ๊ณ ๋žญ์ง€์—์„œ ์œ ๊ธฐ๋† ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๊ธฐ๋กœ ํ•˜์˜€๋‹ค. ๋†์•ฝ์„ ์“ฐ์ง€ ์•Š๊ณ  ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๋ ค๋ฉด ๋ฐฐ์ถ”๋ฅผ ํ•ด์ถฉ์œผ๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ํ•œ๋‚˜๋Š” ํ•ด์ถฉ ๋ฐฉ์ง€์— www.acmicpc.net ํ’€์ด) import sys sys.setrecursionlimit(100000000) T = int(input()) cnt_lst = [] for t in range(T) : m,n,k = map(int,input().split()) cab = [list(map(int,input().split())) for _ in range(k)] map_ = [[0]*m for _ in range(n)] for i,j in cab : map_[j][i..

[๋ฐฑ์ค€ 1012] [dfs/bfs] ์œ ๊ธฐ๋† ๋ฐฐ์ถ”

๐Ÿ’ป ๋ฐฑ์ค€ 1012๋ฒˆ [์œ ๊ธฐ๋† ๋ฐฐ์ถ”] 1012๋ฒˆ: ์œ ๊ธฐ๋† ๋ฐฐ์ถ” ์ฐจ์„ธ๋Œ€ ์˜๋†์ธ ํ•œ๋‚˜๋Š” ๊ฐ•์›๋„ ๊ณ ๋žญ์ง€์—์„œ ์œ ๊ธฐ๋† ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๊ธฐ๋กœ ํ•˜์˜€๋‹ค. ๋†์•ฝ์„ ์“ฐ์ง€ ์•Š๊ณ  ๋ฐฐ์ถ”๋ฅผ ์žฌ๋ฐฐํ•˜๋ ค๋ฉด ๋ฐฐ์ถ”๋ฅผ ํ•ด์ถฉ์œผ๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ํ•œ๋‚˜๋Š” ํ•ด์ถฉ ๋ฐฉ์ง€์— www.acmicpc.net ํ’€์ด) import sys sys.setrecursionlimit(100000000) T = int(input()) cnt_lst = [] for t in range(T) : m,n,k = map(int,input().split()) cab = [list(map(int,input().split())) for _ in range(k)] map_ = [[0]*m for _ in range(n)] for i,j in cab : map_[j][i..

[๋ฐฑ์ค€ 2331] [dfs] ๋ฐ˜๋ณต์ˆ˜์—ด

๐Ÿ’ป ๋ฐฑ์ค€ 2331๋ฒˆ [๋ฐ˜๋ณต์ˆ˜์—ด] 2331๋ฒˆ: ๋ฐ˜๋ณต์ˆ˜์—ด ์ฒซ์งธ ์ค„์— ๋ฐ˜๋ณต๋˜๋Š” ๋ถ€๋ถ„์„ ์ œ์™ธํ–ˆ์„ ๋•Œ, ์ˆ˜์—ด์— ๋‚จ๊ฒŒ ๋˜๋Š” ์ˆ˜๋“ค์˜ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. www.acmicpc.net ํ’€์ด) ์ฒซ๋ฒˆ์งธ ์ œ์ถœ : ๋Ÿฐํƒ€์ž„์—๋Ÿฌ(ModuleNotFoundError) ๋œธ ์•Œ๊ณ ๋ณด๋‹ˆ ๋ฐฑ์ค€์—์„œ๋Š” numpy๋ฅผ ๋ชป ์“ฐ๊ฒŒ ํ•จ...;;^^ # ์ฒซ๋ฒˆ์งธ import numpy as np a,p = map(int,input().split()) visited = {} stack = [] def cal(a,p) : if a in visited : return stack.pop() else : visited[a] = 1 stack.append(a) return cal(np.sum([int(i)**p for i in str(a)]),p) dup_n = cal..

728x90
๋ฐ˜์‘ํ˜•