목록Python (215)
가오리의 코딩일기
Pluggable View → 플라스크는 기본적으로 데코레이터와 함수 기반으로 API를 작성하며 이를 함수 기반 뷰라고 한다 → 플러거블 뷰(pluggable View)는 장고의 generic view에서 영향을 받아 만들어졌다 # 함수 기반 뷰 @app.route('/users') def userList(): users = User.query.all() return render_template('uers.html', users=users) # 플러거블 뷰 class UserAPI(View): methods = ['GET', 'POST'] def dispatch_request(self): users = User.query.all() return render_template('users.html', obj..
def mergeSort(start, end): global swapCount, A if start < end: mid = (start + end) // 2 mergeSort(start, mid) mergeSort(mid + 1, end) startPoint, midPoint = start, mid + 1 temp = [] while startPoint
n = int(input()) treeTable = [list(map(int, input())) for _ in range(n)] def dfs(x, y, n): checkPoint = treeTable[x][y] for i in range(x, x+n): for j in range(y, y+n): if checkPoint != treeTable[i][j]: checkPoint = -1 break if checkPoint == -1: print('(', end='') n //= 2 dfs(x, y, n) dfs(x, y+n, n) dfs(x+n, y, n) dfs(x+n, y+n, n) print(')', end='') elif checkPoint == 1: print(1, end='') else: pr..
import sys sys.setrecursionlimit(10**6) def dfs(x,y): # 상하좌우+대각선 dx = [1,1,-1,-1,1,-1,0,0] dy = [0,1,0,1,-1,-1,1,-1] table[x][y]= 0 for i in range(8): nx = x+dx[i] ny = y+dy[i] if (0
n = int(input()) def hanoi(n, a, b, c): if n==1: print(a, c) else: hanoi(n-1, a, c, b) print(a, c) hanoi(n-1, b, a, c) result = 1 for i in range(n-1): result = result *2+1 print(result) hanoi(n,1,2,3)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) n = int(input()) visited = [False] * (n+1) graph = [[] for _ in range(n+1)] for i in range(n-1): num1, num2 = map(int, input().split()) graph[num1].append(num2) graph[num2].append(num1) def dfs(x): for i in graph[x]: if visited[i] == 0: visited[i] = x dfs(i) dfs(1) for i in range(2, n+1): print(visited[i])
n = int(input()) paper = [list(map(int, input().split())) for _ in range(n)] minus = 0 zero = 0 plus = 0 def dividePaper(x, y, n): global minus, zero, plus checkNumber = paper[x][y] for i in range(x, x+n): for j in range(y, y+n): if paper[i][j] != checkNumber: for k in range(3): for l in range(3): dividePaper(x+k*n//3, y+l*n//3, n//3) return None if checkNumber == -1: minus += 1 elif checkNumber..
bisect: 파이썬 내장 이진탐색 모듈 bisect_left(literable, value): 왼쪽 인덱스 구하기 bisect_right(literable, value): 오른쪽 인덱스 구하기 from bisect import bisect_left, bisect_right n = int(input()) card = sorted(map(int, input().split())) m = int(input()) compare = list(map(int, input().split())) def count_by_range(array, leftValue, rightValue): rightIndex = bisect_right(array, rightValue) leftIndex = bisect_left(array, l..
n = int(input()) tree = [[0] * 3 for _ in range(26)] def preorder(x): # root -> left -> right print(x, end='') if tree[ord(x)-65][1] != '.': preorder(tree[ord(x)-65][1]) if tree[ord(x)-65][2] != '.': preorder(tree[ord(x)-65][2]) def inorder(x): # left -> root -> right if tree[ord(x)-65][1] != '.': inorder(tree[ord(x)-65][1]) print(x, end='') if tree[ord(x)-65][2] != '.': inorder(tree[ord(x)-65][..