YottaGin

Freedom is a responsible choice.

[Python] ABC004 C

2019/3/26 2019/4/17 プログラミング

C – 入れ替え

n = int(input())

n = n % 30

lst_num = ['1', '2', '3', '4', '5', '6']

for i in range(n):
    first = i % 5 + 1
    second = i % 5 +2
    lst_num[first-1], lst_num[second-1] = lst_num[second-1], lst_num[first-1]

print(int(''.join(lst_num)))

メモ

  • pythonで変数のswap(入れ替え)について考えて検討してみた

Atcoder, Python GinO

関連記事

[Python] ABC018 A

問題 A - 豆まき 回答 A = int(input()) B = int(input()) C = int(input()) l = l_sorted = sorted(l) for num in l: print(l_sorted.in...

記事を読む

[グラフ ] クラスカル法をPythonで実装

Python でクラスカル法を実装します。 SciPy で最小全域木を求める時はクラスカル法を使っています。 scipy.sparse.csgraph.minimum_spanning_tree Vertex と Edge 与えられた...

記事を読む

[Python] ABC008 D

問題 D - 金塊ゲーム 回答 80点回答 分割統治法 再帰 分割された区域に再帰的に関数を適用することで問題を解きます。 def rec_get_golds(x_min, y_min, x_max, y_max): ''' ...

記事を読む

[Python] Educational DP Contest H – Grid 1

問題 H - Grid 1 DP、数え上げ問題。 回答 import sys # input処理を高速化する input = sys.stdin.readline def main(): # input H, W = map(int,...

記事を読む

[Python] ABC010 B

問題 B - 花占い 回答 余りを利用する n = int(input()) a = list(map(int, input().split())) count = 0 for i in range(n): for j in range(a, ...

記事を読む


Public Domain YottaGin No Rights Reserved.