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

関連記事

GridSearchCV で LGBM の Categorical Feature を使う際のエラー

sklearn の GridSearchCV を LightGBM で使おうとした時、 GridSearch へ Categorical Feature を渡そうとすると “categorical_feature keyword has been found in params...

記事を読む

[Python] ABC018 D 30点

問題 D - バレンタインデー 回答 AtCoder Beginner Contest 018 解説 from AtCoder Inc. itertools.combinations を使い、全ての組み合わせを列挙します。 imp...

記事を読む

[Python] Punctuationの一括削除

punctuationとは、記号文字列のことです。 str.translate() を使う方法と、正規表現を使う方法で行ってみます。 str.translate() を使うPunctuationの削除 str.translate()を使い、Punctuat...

記事を読む

[Python] 穴掘り法による迷路生成

迷路生成のアルゴリズム 迷路生成のアルゴリズムは数多くあります。 Maze Classification -Maze Creation Algorithms 迷路生成の各種アルゴリズムのC++実装 (Win/Mac両対応) 前回は棒倒し法を用いて迷路を作...

記事を読む

[Python] ABC015 D 全探索 0点

問題 D - 高橋くんの苦悩 回答 TLE で 0点ですが、まずは再帰的に行う全探索を考えます。 p32 です。 W = int(input()) N, K = map(int, input().split()) AB = de...

記事を読む


Public Domain YottaGin No Rights Reserved.