Skip to content

Instantly share code, notes, and snippets.

@kusano
kusano / pointer.cpp
Last active August 29, 2015 14:19
メンバ変数への汎用ポインタ
struct A {
int a;
};
int main()
{
A a;
int *p0 = &a.a; // OK
void *p1 = &a.a; // OK
int A::*p2 = &A::a; // OK
@kusano
kusano / pointer.cpp
Created April 21, 2015 13:16
メンバ変数への汎用ポインタ
struct A {
int a;
};
int main()
{
A a;
int *p0 = &a.a; // OK
void *p1 = &a.a; // OK
int A::*p2 = &A::a; // OK
@kusano
kusano / SmallPolygons.cpp
Created May 4, 2015 17:32
2015 TopCoder Open - Round 1
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
class SmallPolygons
{
@kusano
kusano / A-small.py
Created May 10, 2015 11:34
Google Code Jam 2015 Round 1C
def check(R,C,W,B):
c = sum(b.count(1) for b in B)
for y in range(R):
for x in range(C-W+1):
if B[y][x:x+W].count(1)==c and B[y][x:x+W].count(-1)==0:
return True
return False
def BT(R,C,W,B):
Bt = tuple(tuple(b) for b in B)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <shellapi.h>
#include <tchar.h>
#include <locale.h>
#include <cstdio>
#include <vector>
#include <cassert>
#pragma comment(lib, "shell32.lib")
@kusano
kusano / A.py
Created May 30, 2015 16:38
Google Code Jam 2015 Round 2
def solve(R, C, B):
ans = 0
for cy in range(R):
for cx in range(C):
if B[cy][cx]!=".":
ok = []
for d in range(4):
x = cx
y = cy
while True:
@kusano
kusano / PathDefense.cpp
Created June 8, 2015 17:14
2015 TopCoder Open Marathon - Round 2
// http://community.topcoder.com/longcontest/?module=ViewProblemStatement&compid=48152&rd=16471
#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <cctype>
#include <cstdlib>
#include <numeric>
#include <algorithm>
@kusano
kusano / Cyclemin.cpp
Created June 8, 2015 17:45
TopCoder C++11
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
constexpr int f(int a) {return a+a;}
int v[f(10)];
class Cyclemin{public:
string bestmod(string s, int k)
@kusano
kusano / mynumber.py
Created June 22, 2015 16:48
マイナンバーの最下位桁の出現頻度を調べる
#coding: utf-8
# マイナンバーの最下位桁の出現頻度を調べる
# http://law.e-gov.go.jp/announce/H26F11001000085.html
import random
def check(number):
P = map(int, ("%011d"%number)[::-1])
Q = [n+1 if n<=6 else n-5 for n in range(1,12)]
r = sum(p*q for p,q in zip(P,Q)) % 11
@kusano
kusano / gist:8ac361ff111643c04ea9
Created July 9, 2015 08:17
コメントの書き方
// コメントX
A;
B;
C;
// コメントを書くまでもない処理だけど、コメントXがDまで対象にしていると
// 思われると困るので、ここにもコメントを書きたくなる
D;