Skip to content

Instantly share code, notes, and snippets.

View MitI-7's full-sized avatar

MitI_7 MitI-7

View GitHub Profile
#include <iostream>
#include <vector>
#include <map>
using namespace std;
struct Node {
map<char, int> next; // nodeの両端にcharをつけたときにいくnodeのindex
int len = 0; // 回文の長さ
int sufflink = 0; // nodeのsuffix palindromeであるnodeのindex
@MitI-7
MitI-7 / multikey_quick_sort.cpp
Last active January 24, 2016 04:54
Multikey quicksortとかTernary quicksortとか呼ばれるやつ.(参考: 続・アルゴリズムを学ぼう 4.7 接尾辞配列(SuffixArray))
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <assert.h>
using namespace std;
// pivotを選ぶ.
char find_pivot_char(vector<string> &data, int left, int right, int depth) {
greed {
codeRoot = "../topcoder"
logging {
logLevel = OFF
logToStderr = true
logFolder = Logs
}
backup {
@MitI-7
MitI-7 / RunLengthEncoding.py
Created December 30, 2015 09:08
Run Length Encoding
from itertools import groupby
def encoding_rle(s):
return "".join((k + str(len(list(g)))) for k, g in groupby(s))
def decoding_rle(s):
return "".join(s[i] * int(s[i + 1]) for i in range(0, len(s), 2))
@MitI-7
MitI-7 / PC_OP_RS1.py
Created December 23, 2015 05:07
PC-OP-RS1をpythonから操作する
import serial
from struct import *
from binascii import *
class PC_OP_RS1:
def __init__(self, port):
self._ser = serial.Serial(port, 115200, timeout=1)
self._LED = pack('B', 0x69) # LED点灯
@MitI-7
MitI-7 / ftdiport.inf
Created December 23, 2015 04:33
PC-OP-RS1をWindows10で使えるように修正
; FTDIPORT.INF
;
; Copyright ゥ 2000-2015 Future Technology Devices International Limited
;
; USB serial port driver installation file for Windows 2000, XP, Server 2003, Vista, Server 2008,
; Windows 7, Server 2008 R2, Windows 8, Windows 8.1 and Server 2012 R2.
;
;
; IMPORTANT NOTICE: PLEASE READ CAREFULLY BEFORE INSTALLING THE RELEVANT
; SOFTWARE: This licence agreement (Licence) is a legal agreement between you (Licensee or
@MitI-7
MitI-7 / ftdibus.inf
Created December 23, 2015 04:32
PC-OP-RS1をWindows10で使えるように修正
; FTDIBUS.INF
;
; Copyright ゥ 2000-2015 Future Technology Devices International Limited
;
; USB serial converter driver installation file for Windows 2000, XP, Server 2003, Vista, Server 2008,
; Windows 7, Server 2008 R2, Windows 8, Windows 8.1 and Server 2012 R2.
;
;
; IMPORTANT NOTICE: PLEASE READ CAREFULLY BEFORE INSTALLING THE RELEVANT
; SOFTWARE: This licence agreement (Licence) is a legal agreement between you (Licensee or
import numpy as np
from sklearn.cluster import KMeans
class Cluster:
def __init__(self, ids: [str], features: [[float]], centroid: []):
self.ids = np.array(ids)
self.features = np.array(features)
self.centroid = centroid
@MitI-7
MitI-7 / viterbi.py
Created May 27, 2015 06:41
ビタビアルゴリズムでN-bestをだす
import sys
from collections import defaultdict
import queue
class Node:
def __init__(self, id_, name, weight):
self.id = id_
self.name = name
self.weight = weight
import sys
# 各ノードのコスト
nodes = {"BOS": 0, "EOS": 0,
"さ": 100, "さか": 200, "さかな": 100, "かな": 200, "なだ": 200, "だ": 10, "よ": 10}
# ノードのつながりのコスト
edges = {("BOS", "さ"): 30,
("BOS", "さか"): 30,
("BOS", "さかな"): 30,