BAEKJOON : 10819, 7562, 1991, 2292
No. 10819
1. Problem
2. My Solution
import sys
def permutation(level):
if level >= n:
res.append(sum(arr.copy()))
else:
for i in range(n):
if visited[i] == True:
continue
visited[i] = True
arr[level] = nums[i]
permutation(level+1)
visited[i] = False
def sum(arr):
temp = 0
for i in range(len(arr)-1):
temp += abs(arr[i] - arr[i+1])
return temp
n = int(sys.stdin.readline())
nums = list(map(int,sys.stdin.readline().rstrip().split()))
arr = [0] * n
visited = [False] * n
res = []
permutation(0)
print(max(res))
No. 7562
1. Problem
2. Others' Solutions
import sys
from collections import deque
def bfs(x,y):
queue = deque()
queue.append((x,y))
chess[x][y] = 0 # 원점으로 다시오는 것을 제거
while(queue):
x,y = queue.popleft()
for dx, dy in move:
nx = x + dx
ny = y + dy
# 제일 먼저 해당 좌표값을 수정하는 경로가 최단거리임
if 0 <= nx < i and 0 <= ny < i and chess[nx][ny] == 1: # 아직 아무도 방문하지 않았다면
chess[nx][ny] = chess[x][y] + 1
queue.append((nx,ny))
if nx == target_x and ny == target_y:
return chess[nx][ny]
test_n = int(sys.stdin.readline())
for _ in range(test_n):
i = int(sys.stdin.readline())
target_x, target_y = map(int,sys.stdin.readline().rstrip().split())
present_x, present_y = map(int,sys.stdin.readline().rstrip().split())
chess = [[1]*i for _ in range(i)]
move = [(-2,1),(-1,2),(1,2),(2,1),(2,-1),(1,-2),(-1,-2),(-2,-1)]
if target_x == present_x and target_y == present_y:
print(0)
else:
print(bfs(present_x, present_y))
3. Learned No. 1991
1. Problem
2. My Solution
import sys
sys.setrecursionlimit(10**8)
def preorder(index):
if index < len(tree):
if tree[index] != '.':
result[0].append(tree[index])
preorder(index*2+1)
preorder(index*2+2)
def inorder(index):
if index < len(tree):
inorder(index*2+1)
if tree[index] != '.':
result[1].append(tree[index])
inorder(index*2+2)
def postorder(index):
if index < len(tree):
postorder(index*2+1)
postorder(index*2+2)
if tree[index] != '.':
result[2].append(tree[index])
n = int(sys.stdin.readline())
tree = ['A'] + ['.'] * (2**n -3) # 경사 이진트리일 경우를 대비
result = [[],[],[]]
# 트리를 배열(리스트)에 저장
for i in range(n):
root, left, right = sys.stdin.readline().rstrip().split()
tree[tree.index(root)*2+1] = left
tree[tree.index(root)*2+2] = right
preorder(0)
inorder(0)
postorder(0)
for i in range(3):
print(*result[i], sep='')
import sys
sys.setrecursionlimit(10**8)
def preorder(index):
if dict.get(index) and dict[index] != '.':
result[0].append(dict[index])
preorder(index*2+1)
preorder(index*2+2)
def inorder(index):
if dict.get(index) and dict[index] != '.':
inorder(index*2+1)
result[1].append(dict[index])
inorder(index*2+2)
def postorder(index):
if dict.get(index) and dict[index] != '.':
postorder(index*2+1)
postorder(index*2+2)
result[2].append(dict[index])
n = int(sys.stdin.readline())
dict = { 0: 'A', 'A': 0}
result = [[],[],[]]
for i in range(n):
root, left, right = sys.stdin.readline().rstrip().split()
dict[dict[root]*2+1], dict[left] = left, dict[root]*2+1
dict[dict[root]*2+2], dict[right] = right, dict[root]*2+2
preorder(0)
inorder(0)
postorder(0)
for i in range(3):
print(*result[i], sep='')
3. Learned No. 2292
1. Problem
import sys
n = int(sys.stdin.readline())
level = 0
level_max = 1
if n == 1:
print(0)
else:
while(n > level_max):
level_max += (6 * level)
level += 1
print(level)
3. Learned -aがb以下=aがb以下
-aはbより大きいか=aがbより小さいか...など
Reference
この問題について(BAEKJOON : 10819, 7562, 1991, 2292), 我々は、より多くの情報をここで見つけました https://velog.io/@codren/BAEKJOON-10819テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol