본문 바로가기

PS/백준46

백준 1991번 트리순회 python 파이썬 1. 문제 https://www.acmicpc.net/problem/1991 1991번: 트리 순회 첫째 줄에는 이진 트리의 노드의 개수 N(1≤N≤26)이 주어진다. 둘째 줄부터 N개의 줄에 걸쳐 각 노드와 그의 왼쪽 자식 노드, 오른쪽 자식 노드가 주어진다. 노드의 이름은 A부터 차례대로 영문자 www.acmicpc.net 2. 풀이 3. 구현 import sys #sys.stdin=open('input.txt') n = int(sys.stdin.readline().strip()) tree={} while n: n-=1 root,left,right = sys.stdin.readline().strip().split() tree[root] = [left, right] def preorder(root): .. 2021. 8. 6.
백준 11725번: 트리의 부모찾기 python 파이썬 1. 문제 https://www.acmicpc.net/problem/11725 11725번: 트리의 부모 찾기 루트 없는 트리가 주어진다. 이때, 트리의 루트를 1이라고 정했을 때, 각 노드의 부모를 구하는 프로그램을 작성하시오. www.acmicpc.net 2. 풀이 3. 구현 import sys # sys.stdin = open('input.txt') sys.setrecursionlimit(10**8) # @profile def main(): n = int(sys.stdin.readline()) tree=[[] for _ in range(n+2)] tmp=n while tmp>1: tmp-=1 n_1, n_2 = map(int, sys.stdin.readline().split()) tree[n_1]... 2021. 8. 6.
백준 2250번: 트리의 높이와 너비 python 파이썬 1.문제 https://www.acmicpc.net/problem/2250 2250번: 트리의 높이와 너비 첫째 줄에 노드의 개수를 나타내는 정수 N(1 ≤ N ≤ 10,000)이 주어진다. 다음 N개의 줄에는 각 줄마다 노드 번호와 해당 노드의 왼쪽 자식 노드와 오른쪽 자식 노드의 번호가 순서대로 주어진다. www.acmicpc.net 2. 풀이 3. 구현 import sys # sys.stdin=open('input.txt') sys.setrecursionlimit(10**7) class node: def __init__(self): self.left=0 self.right=0 self.depth=0 self.order=0 max_depth=-1 order=0 # @profile def main():.. 2021. 8. 6.
[반례모음] 백준 2839번: 설탕 배달 python 파이썬 1. 문제 https://www.acmicpc.net/problem/2839 2839번: 설탕 배달 상근이는 요즘 설탕공장에서 설탕을 배달하고 있다. 상근이는 지금 사탕가게에 설탕을 정확하게 N킬로그램을 배달해야 한다. 설탕공장에서 만드는 설탕은 봉지에 담겨져 있다. 봉지는 3킬로그 www.acmicpc.net 2. 풀이 DP 3. 구현 import sys # sys.stdin = open('input.txt') import math target = int(sys.stdin.readline().strip()) lis = [math.inf]*5002 lis[3] = 1 lis[5] = 1 for i in range(6, target+1): lis[i] = min(lis[i-3]+1, lis[i-5]+1) .. 2021. 8. 6.
반응형