목록Python/백준 (129)
가오리의 코딩일기
n = int(input()) graph = [] house = [] for _ in range(n): graph.append(list(map(int, input()))) dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] def dfs(x, y): if x = n or y = n: return False if graph[x][y] == 1: global count count += 1 graph[x][y] = 0 for i in range(4): nx = x + dx[i] ny = y + dy[i] dfs(nx, ny) return True return False count = 0 result = 0 for i in range(n): for j in r..
import sys sys.setrecursionlimit(10000) # 재귀 한도 풀어주기 def dfs(start): visited[start] = True node = graph[start] if not visited[node]: dfs(node) testCase = int(sys.stdin.readline()) for _ in range(testCase): n = int(sys.stdin.readline()) graph = [0] + list(map(int, sys.stdin.readline().split())) visited = [True] + [False] * n result = 0 for i in range(1, n+1): if not visited[i]: dfs(i) result += 1..
import sys from collections import deque def bfs(start): queue = deque([start]) visited[start] = True while queue: node = queue.popleft() for i in graph[node]: if not visited[i]: queue.append(i) visited[i] = True n,m = map(int, sys.stdin.readline().split()) graph = [ [] for _ in range(n+1)] for _ in range(m): u, v = map(int, sys.stdin.readline().split()) graph[u].append(v) graph[v].append(u) vis..
import sys string = list(input()) stringList = [] n = int(input()) for i in range(n): command = sys.stdin.readline().split() if command[0] == "L" and string: stringList.append(string.pop()) elif command[0] == "D" and stringList: string.append(stringList.pop()) elif command[0] == "B" and string: string.pop() elif command[0] == "P": string.append(command[1]) print("".join(string + list(reversed(st..
n, k = map(int, input().split()) result = [] numberList = [i for i in range(1, n+1)] number = 0 for i in range(n): number += (k-1) if number >= len(numberList): number %= len(numberList) result.append(str(numberList[number])) numberList.pop(number) print("", sep="")
import math a, b = map(int, input().split()) print("1"*math.gcd(a, b))
import math testCase = int(input()) for i in range(testCase): numberList = list(map(int, input().split())) result = 0 for j in range(1, len(numberList)): for k in range(j+1, len(numberList)): result += math.gcd(numberList[j], numberList[k]) print(result)
a, b = map(int, input().split()) m = int(input()) alist = list(map(int, input().split())) A = 0 for i in range(m): A += alist[m-i-1]*a**i result = '' while A: result = ' '+result result = str(A % b)+result A //= b print(result)
n = int(input()) if not n: print('0') exit() result = '' while n: if n % (-2): result = '1' + result n = n//(-2) + 1 else: result = '0' + result n //= -2 print(result)