Solve AtCoder ABC168 with python (A ~ D)

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

Solve AtCoder ABC168 with python (A ~ D)
Solve ABC166 A ~ D with Python
[AtCoder] Solve ABC1 ~ 100 A problem with Python
Solve AtCoder ABC166 with python
AtCoder ABC 182 Python (A ~ D)
Solve AtCoder ABC 186 with Python
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
Solve ABC163 A ~ C with Python
Solve ABC168 A ~ C with Python
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Solve AtCoder 167 with python
Solve ABC165 A, B, D in Python
Solve with Ruby and Python AtCoder ABC133 D Cumulative sum
AtCoder ABC 177 Python (A ~ E)
AtCoder ABC 176 Python (A ~ E)
Solve ABC175 D in Python
I wanted to solve the ABC164 A ~ D problem with Python
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
Solve Atcoder ABC176 (A, B, C, E) in Python
Solve Atcoder ABC169 A-D in Python
Solve AtCoder Problems Recommendation with python (20200517-0523)
Solve ABC036 A ~ C in Python
Solved AtCoder ABC 114 C-755 with Python3
Template AtCoder ABC 179 Python (A ~ E)
Solve ABC037 A ~ C in Python
AtCoder ABC 174 Python
[AtCoder explanation] Control the A, B, (C), D problems of ABC165 with Python!
[AtCoder explanation] Control the A, B, C, D problems of ABC183 with Python!
Solve with Ruby and Python AtCoder ABC084 D Cumulative sum of prime numbers
AtCoder ABC187 Python
AtCoder ABC188 Python
[AtCoder explanation] Control the A, B, C, D problems of ABC181 with Python!
AtCoder ABC 175 Python
[AtCoder explanation] Control ABC180 A, B, C problems with Python!
Solving with Ruby and Python AtCoder ABC178 D Dynamic programming
Solving with Ruby and Python AtCoder ABC151 D Breadth-first search
[AtCoder explanation] Control ABC158 A, B, C problems with Python!
Solving with Ruby and Python AtCoder ABC138 D Adjacency list
[AtCoder explanation] Control ABC164 A, B, C problems with Python!
[AtCoder explanation] Control ABC168 A, B, C problems with Python!
Solve ABC175 A, B, C in Python
ABC 157 D --Solve Friend Suggestions in Python!
I wanted to solve ABC160 with Python
I wanted to solve ABC172 with Python
Solving with Ruby, Python and networkx AtCoder ABC168 D Adjacency list
Solve Sudoku with Python
Solve ABC169 in Python
Solve POJ 2386 with python
Solve "AtCoder version! Ant book (beginner)" with Python!
[AtCoder explanation] Control the A, B, C problems of ABC182 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC186 with Python!
Solving with Ruby, Perl, Java and Python AtCoder ABC 165 D Floor function
[AtCoder explanation] Control the A, B, C problems of ABC185 with Python!
Solving with Ruby, Perl, Java and Python AtCoder ABC 131 D Array Sorting
Solve with Ruby, Perl, Java and Python AtCoder ABC 047 C Regular Expression
[AtCoder explanation] Control the A, B, C problems of ABC187 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC184 with Python!
[Python] Solve equations with sympy
Light blue with AtCoder @Python