- オープンクラス
class String
def hello
'hello'
end
end
"a".hello # => 'hello'
class D
def a; end
def prufer_to_tree(A): | |
n = len(A) | |
G = [[] for i in range(n+2)] | |
deg = [1]*(n+2) | |
for a in A: | |
deg[a] += 1 | |
E = [] | |
for a in A: | |
for i in range(n+2): |
# AtCoder: ACした問題の中でPythonでACしていない問題を列挙 | |
# "https://kenkoooo.com/atcoder/atcoder-api/results?user=(ユーザー名)"のデータを"results.txt"として保存して利用 | |
import json, re | |
with open('results.txt', 'r') as f: | |
txt = f.read() | |
data = json.loads(txt) | |
ps = {} | |
qs = {} |
class String
def hello
'hello'
end
end
"a".hello # => 'hello'
class D
def a; end
print "> " | |
obj = eval(gets) # '1'とか | |
puts "#{obj} #{obj.class}" | |
puts | |
klass = obj.class | |
while !klass.nil? | |
# インスタンスメソッド | |
puts "== #{klass} #{klass.instance_methods(false)}" |
# AC (http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2434976#1) | |
# BFS二回で求める解法: 計算量 O(N) | |
from collections import deque | |
n = input() | |
G = [[] for i in xrange(n)] | |
for i in xrange(n-1): | |
s, t, w = map(int, raw_input().split()) | |
G[s].append((t, w)) | |
G[t].append((s, w)) | |
#!/bin/bash | |
# ICPCの回答チェック (diffを取る) | |
# usage: sh domestic-2017.sh "python a.py" A | |
name="domestic-2017" | |
in_ext="in" | |
out_ext="diff" | |
# コードの実行コマンド: 例) "python a.py" |
#include <bits/stdc++.h> | |
using namespace std; | |
#define rep(i,n) for(int i=0;i<(n);i++) | |
#define fi first | |
#define se second | |
#define pb push_back | |
#define mp make_pair | |
using vi = vector<int>; |
3**3 # => 9
3x3 # => "333"
"a"x3 # => "aaa"
1."a" # => "1a"
# 文字列や数値は随時キャストされる
10 x 3 * 5 # => 505050
# encoding: utf-8 | |
# うまくFMTを計算するためのパラメタを決定する | |
# nを決めて、うまいPとωを決定する | |
# Pは素数であること、ωのn回の積で循環すること (ω^n ≡ 1 (mod P))が条件 | |
n = 2**18 | |
from math import sqrt | |
for x in xrange(1000, 2000): | |
P = x*n + 1 |