A Take out the 1st place and divide the case.
# A
N = int(input())
n = N % 10
if n in [2, 4, 5, 7, 9]:
print('hon')
elif n in [0, 1, 6, 8]:
print('pon')
else:
print('bon')
B Compare the length of S with K.
# B
K = int(input())
S = input()
len_S = len(S)
if len_S <= K:
print(S)
else:
print(S[:K] + '...')
C Just use trigonometric functions.
# C
A, B, H, M = list(map(int, input().split()))
import math
A_x = A * math.cos(2 * math.pi * (H + M / 60.) / 12.)
A_y = A * math.sin(2 * math.pi * (H + M / 60.) / 12.)
B_x = B * math.cos(2 * math.pi * M / 60.)
B_y = B * math.sin(2 * math.pi * M / 60.)
print('{:.15f}'.format(math.sqrt((A_x - B_x) ** 2 + (A_y - B_y) ** 2)))
D You can easily find it by doing a breadth-first search. However, be aware that creating an adjacency matrix will use a lot of time and memory. At first I thought I should use the information obtained by predecessors = True in scipy's shortest_path, but it didn't work (WA). .. .. I thought it would work because I should only have to find the shortest path. .. ..
# D
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import breadth_first_order
N, M = list(map(int, input().split()))
ABs = np.array([list(map(int, input().split())) for i in range(M)])
row = ABs.T[0]-1
col = ABs.T[1]-1
data = [1] * (M)
csr = csr_matrix((data, (row, col)), shape=(N, N))
_, proc = breadth_first_order(csr, 0, directed=False)
if -9999 in proc[1:]:
print('No')
else:
print('Yes')
print('\n'.join((proc[1:]+1).astype('str')))
Recommended Posts