0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

個人的メモ

Last updated at Posted at 2022-02-23

bit全探索(itertoolsを使う)

from itertools import product

for pro in product((0, 1), repeat=n):  #長さnの各要素が0か1のタプルを返す=bit全探索で便利
    print(pro)

二分探索(bisectを使う)

import bisect
list = [10, 20, 30, 40]
bisect.bisect(list, 25)
2

inputする

import sys
input = sys.stdin.readline

文字の種類を数える

n = int(input())
from collections import defaultdict
dic = defaultdict(int)
for _ in range(n):
    dic[input()]+=1

特定の行・列を省いたマス目を出力する

for i in range(h):
    if i not in d:  #dは省く行のインデックスが入っているリスト
        ll = [a[i][j] for j in range(w) if j not in e] #eは省く列のインデックスが入っているリスト
        print("".join(ll))

数列の隣接する k 項の和を求める

a = 0
for i in range(k):   #最初のk項の和を求める
    a += p[i]

l = [a]   #和を入れるリスト

for i in range(n-k):   #k項の内最初の項を引き, k項の最後の次の項を足す
    a = a - p[i] + p[k+i]
    l.append(a)

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?