Löse AtCoder ABC168 mit Python (A ~ D)

A Nehmen Sie den 1. Platz heraus und teilen Sie den Fall.

# 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 Vergleichen Sie die Länge von S mit K.

# B

K = int(input())
S = input()

len_S = len(S)
if len_S <= K:
    print(S)
else:
    print(S[:K] + '...')

C Sofort, wenn Sie eine Dreiecksfunktion verwenden.

# 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 Es kann leicht gefunden werden, indem eine Suche nach Breitenpriorität durchgeführt wird. Beachten Sie jedoch, dass das Erstellen einer benachbarten Matrix viel Zeit und Speicher benötigt. Zuerst dachte ich, ich sollte die Informationen der Vorgänger = True in scipys kürzestem Pfad verwenden, aber es hat nicht funktioniert (WA). .. .. Ich dachte, es würde funktionieren, weil ich nur den kürzesten Weg finden müsste. .. ..

# 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

Löse AtCoder ABC168 mit Python (A ~ D)
Löse ABC166 A ~ D mit Python
[AtCoder] Löse ABC1 ~ 100 Ein Problem mit Python
Löse AtCoder ABC166 mit Python
AtCoder ABC 182 Python (A ~ D)
[AtCoder] Lösen Sie ein Problem von ABC101 ~ 169 mit Python
Löse ABC163 A ~ C mit Python
Löse ABC168 A ~ C mit Python
Löse ABC162 A ~ C mit Python
Löse ABC167 A ~ C mit Python
Löse ABC158 A ~ C mit Python
Löse AtCoder 167 mit Python
Löse ABC165 A, B, D mit Python
Lösen mit Ruby und Python AtCoder ABC133 D Kumulative Summe
AtCoder ABC 177 Python (A ~ E)
AtCoder ABC 176 Python (A ~ E)
Löse ABC175 D in Python
Ich wollte das ABC164 A ~ D-Problem mit Python lösen
Fordern Sie AtCoder (ABC) 164 mit Python heraus! A ~ C Problem
Löse den Atcoder ABC176 (A, B, C, E) in Python
Löse den Atcoder ABC169 A-D mit Python
Beheben von AtCoder-Problemen Empfehlung mit Python (20200517-0523)
Löse ABC036 A ~ C mit Python
AtCoder ABC 114 C-755 mit Python3 gelöst
Vorlage AtCoder ABC 179 Python (A ~ E)
Löse ABC037 A ~ C mit Python
AtCoder ABC 174 Python
[Erklärung zum AtCoder] Kontrollieren Sie die A-, B-, (C), D-Probleme von ABC165 mit Python!
[AtCoder-Erklärung] Kontrollieren Sie die A-, B-, C- und D-Probleme von ABC183 mit Python!
Lösen mit Ruby und Python AtCoder ABC084 D Kumulative Summe der Primzahlen
[Erklärung zum AtCoder] Kontrollieren Sie die A-, B-, C- und D-Probleme von ABC181 mit Python!
AtCoder ABC 175 Python
[AtCoder Erklärung] Kontrollieren Sie ABC180 A, B, C Probleme mit Python!
Lösen mit Ruby und Python AtCoder ABC178 D Dynamische Planungsmethode
Lösen mit Ruby und Python AtCoder ABC151 D Suche nach Breitenpriorität
[AtCoder Erklärung] Kontrollieren Sie ABC158 A, B, C Probleme mit Python!
Lösen mit Ruby und Python AtCoder ABC138 D Benachbarte Liste
[AtCoder Erklärung] Kontrollieren Sie ABC164 A, B, C Probleme mit Python!
[AtCoder Erklärung] Kontrollieren Sie ABC168 A, B, C Probleme mit Python!
Löse ABC175 A, B, C mit Python
ABC 157 D - Lösungsvorschläge für Freunde in Python!
Ich wollte ABC160 mit Python lösen
Ich wollte ABC172 mit Python lösen
Lösen mit Ruby, Python und networkx AtCoder ABC168 D Benachbarte Liste
Löse Mathe mit Python
Löse ABC169 mit Python
Löse POJ 2386 mit Python
Löse "AtCoder Version! Arimoto (Anfänger)" mit Python!
[Erklärung zum AtCoder] Kontrollieren Sie die A-, B- und C-Probleme von ABC182 mit Python!
AtCoder ABC 165 D Bodenfunktion in Ruby, Perl, Java und Python gelöst
Lösen mit Ruby, Perl, Java und Python AtCoder ABC 131 D Sortieren von Arrays
Lösen mit Ruby, Perl, Java und Python AtCoder ABC 047 C Regulärer Ausdruck
[AtCoder Erklärung] Kontrollieren Sie ABC184 A, B, C Probleme mit Python!
[Python] Löse Gleichungen mit Sympy
Hellblau mit AtCoder @Python