Skip to content

Instantly share code, notes, and snippets.

View naoppy's full-sized avatar
💭
Study at School

naoppy naoppy

💭
Study at School
  • AKARI Inc.
  • Kita-Ku, Tokyo, Japan
  • X @naoppyj
View GitHub Profile
from typing import List, Optional
# Binomial Min-Heap
# author: Naoki Otani (@naoppyj in GitHub)
# not tested yet
# feel free to ask me if you have any questions, or if you find any bugs
class BinomialHeapNode:
value: int
#include "QTree.h"
#include <random>
#include <climits>
int BitSeparate16(int n)
{
n = (n | (n << 8)) & 0x00ff00ff;
n = (n | (n << 4)) & 0x0f0f0f0f;
n = (n | (n << 2)) & 0x33333333;
n = (n | (n << 1)) & 0x55555555;
import numpy as np
arr = np.array([116, 117, 120, 120, 118, 119, 120, 97, 120, 122, 107, 55, 119, 115, 73, 36])
avg = arr.mean()
print(f"avg : {avg}")
bitplane = np.zeros((16,), dtype=np.int64)
bitplane[arr < avg] = 0
bitplane[arr >= avg] = 1
print(bitplane.reshape(4, 4))
H = arr[bitplane].mean()
@naoppy
naoppy / Trie.kt
Last active October 19, 2019 06:25
/**
* Trie木のノード
*
* @param previousNodeID このノードの直前のノードのID
* @param charSize 追加される文字のあり得る種類の数
*/
class TrieNode(val previousNodeID: Int?, charSize: Int) {
val next = IntArray(charSize) { -1 }
/**
* このノードの子供以下に追加された全ての文字列の個数
import java.util.*
import kotlin.collections.ArrayList
private data class Edge(val to: Int)
fun main() {
val n = 10
val edges = Array(n) {
ArrayList<Edge>()
}
package algorithms.search
/**
* elementをキーとして、キー以上の要素の中で最も小さい位置のインデックスを返す。
* 検索範囲は[fromIndex, toIndex)
*
* @param fromIndex この位置を含む範囲
* @param toIndex この位置を含まない範囲
* @return 0-indexedなインデックス
*/
import kotlin.math.min
/**
* 参考:https://github.com/tatyam-prime/kyopro_library/blob/master/RollingHash.cpp
*/
private val bases =
intArrayOf(257, 262, 266, 275, 276, 281, 285, 290, 296, 302, 306,
310, 311, 313, 323, 333, 344, 345, 350, 357, 367, 370, 373,
402, 423, 425, 431, 440, 442, 443, 454, 457, 458, 462, 471,
@naoppy
naoppy / UnionFind.java
Created June 11, 2019 09:58
UnionFind
public class UnionFind {
private int[] par;
public UnionFind(int v) {
for(int i = 0; i < v; i++) par[i] = i;
}
public int root(int k) {
if(par[k] == k) return k;
else return par[k] = root(par[k]);
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@naoppy
naoppy / list2.c
Last active February 21, 2019 01:05
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct cell {
char word[100];
struct cell *next;
};
typedef struct cell Cell;