This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PriorityQueue: | |
INIT_VALUE = -1 | |
MAX_SIZE = 2000001 | |
def __init__(self): | |
self.heap = [PriorityQueue.INIT_VALUE]*(PriorityQueue.MAX_SIZE + 1) | |
self.size = 0 | |
def insert(self, k): | |
self.size += 1 | |
self.heap[self.size] = k |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dynamic Programming - Longest Common Subsequence | |
q = int(input()) | |
for _ in range(q): | |
X = [''] + list(input()) | |
Y = [''] + list(input()) | |
i,j = len(X),len(Y) | |
# i x j Matrix | |
LCS = [[-1 for a in range(j)] for b in range(i)] | |
for ii in range(i): | |
for jj in range(j): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Graph I - Connected Components | |
# 幅優先探索すればよかった | |
import array | |
from collections import deque | |
def groupify(length, adj_list): | |
group = array.array('l', (-1 for _ in range(length))) | |
g_id = 0 | |
dq = deque() | |
for idx in range(length): | |
if group[idx] == -1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Graph II - Single Source Shortest Path II | |
def dijkstra(length, adj_m): | |
INFTY = float('inf') | |
d = [INFTY for _ in range(length)] | |
d[0] = 0 | |
Q = [i for i in range(length)] | |
while Q: | |
idx = INFTY | |
minv = INFTY | |
for q in Q: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Heuristic Search - 8 Queens Problem | |
"""まだ途中""" | |
NUM = 8 | |
Q = 1 | |
Und = 0 | |
F = 2 | |
k = int(input()) | |
B = [[Und for _ in range(NUM)] for _ in range(NUM)] | |
for _ in range(k): | |
r,c = map(int, input().split()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# よく使う | |
import os | |
import shutil | |
# フォルダの作成 | |
os.mkdir('dir_path') | |
os.makedirs('dir_path') # 中間のディレクトリも作成するときはこっちが便利 | |
# フォルダの移動 移動先までのフォルダは先に作成しておくべき | |
shutil.move('srcfile_path', 'dstfile_path') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python3 | |
# -*- coding: utf-8 -*- | |
import os, shutil | |
def copy_update(from_dir, to_dir, cnt=0): | |
""" | |
再帰的にコピーする。コピー元が新しい時は既存ファイルなら上書きする | |
""" | |
dst_exists = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import matplotlib | |
matplotlib.interactive(True) | |
matplotlib.use('WXAgg') | |
import wx | |
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg | |
from matplotlib.figure import Figure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Display fft data. | |
Environment: | |
matplotlib==2.0.2 | |
numpy==1.13.0 | |
PyAudio==0.2.11 | |
wxPython==4.0.0a3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Flaskを使って、mongodbに保存した画像ファイルを表示させる。 | |
""" | |
# まずはmongoDBのセットアップ | |
from mongoengine import connect |
OlderNewer