This file contains hidden or 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
# yukicoder No.187: "中華風 (Hard)" - http://yukicoder.me/problems/no/187 | |
# AC: http://yukicoder.me/submissions/142514 | |
# おおざっぱな解法 | |
# d_0 = 1, x_0 = 0 とする | |
# A ≡ x_{i-1} (mod d_{i-1}), A ≡ X_i (mod Y_i) について | |
# 中国余剰定理を利用して次のx_i, d_iを計算していく。 | |
# | |
# g_i = gcd(d_{i-1}, Y_i)とする。 | |
# d_{i-1}*x + Y_i*y = g_i となるx, yを拡張ユークリッドの互除法で求める。 |
This file contains hidden or 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
# encoding: utf-8 | |
# フィボナッチ数をKitamasa法で計算してみる | |
# フィボナッチ数列を以下で定義 | |
# a_n = A(n, 0)*a_0 + A(n, 1)*a_1 | |
# A(2, 0) = A(2, 1) = 1; a_0 = 0; a_1 = 1 | |
A2 = (1, 1) | |
# nxt: A(n, *)からA(n+1, *)を計算 |
This file contains hidden or 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
# encoding: utf-8 | |
# problem: http://chokudai002.contest.atcoder.jp/tasks/chokudai002_a | |
# Score: 37616 (http://chokudai002.contest.atcoder.jp/submissions/964911) | |
from math import sqrt | |
import random | |
base = 2*3*5*7*11*13*3*3 | |
N = 100 | |
M = 10000 |
This file contains hidden or 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
id | | | ^ | & | + | - | * | / | % | ~ | ( | ) | ! | $ | O | X | A | E | T | N | F | I | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | s11 | s7 | s9 | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | ||||||||||||
1 | s12 | acc | |||||||||||||||||||||
2 | r2 | s13 | r2 | r2 | |||||||||||||||||||
3 | r4 | r4 | s14 | r4 | r4 | ||||||||||||||||||
4 | r6 | r6 | r6 | s15 | s16 | r6 | r6 | ||||||||||||||||
5 | r9 | r9 | r9 | r9 | r9 | s17 | s18 | s19 | r9 | r9 | |||||||||||||
6 | r14 | r14 | r14 | r14 | r14 | r14 | r14 | r14 | r14 | r14 | |||||||||||||
7 | s11 | s7 | s9 | 20 | 8 | 10 | |||||||||||||||||
8 | r16 | r16 | r16 | r16 | r16 | r16 | r16 | r16 | r16 | r16 |
This file contains hidden or 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 sys | |
from collections import deque | |
INF = 10**9+7 | |
argc = len(sys.argv) | |
N = int(sys.argv[1]) if argc==2 else int(raw_input()) | |
def tcheck(q, c, idx): | |
# (q[i], i) <=> (idx, c) | |
return all(q[i]+i!=idx+c and q[i]-i!=idx-c for i in xrange(c)) | |
q_ = [INF]*N | |
def rotQ(q): |
This file contains hidden or 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
# encoding: utf-8 | |
import cmath | |
# ====================================================== | |
# 通常のDFT O(N^2) | |
def dft(f): | |
exp = cmath.exp | |
pi = cmath.pi | |
N = len(f) |
This file contains hidden or 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
# encoding: utf-8 | |
import random, itertools | |
random.seed() | |
randint = random.randint | |
choice = random.choice | |
shuffle = random.shuffle | |
# n変数によるm個のclauseから成る論理式Fを生成 | |
def make(n, m): |
This file contains hidden or 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
# encoding: utf-8 | |
# a Calculus of Communicating System(CCS)に関して、 | |
# プロセスの関係を判定するために書いたプログラム | |
# たぶんあってる | |
import random | |
random.seed() | |
randint = random.randint | |
# τ(プロセスの内部action)をプロセス生成に含めるか(ここでは't'で表現) | |
tau = True |
This file contains hidden or 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
# AC (http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1893746#1) | |
# P(x1, y1), Q(x2, y2)が通る直線上にR(x, y)を写像した先をSとする | |
# r = (x-x1, y-y1), p = (x2-x1, y2-y1) とすると、Sの座標は(x1, y1) + a*pで表される | |
# この時、a = |r|cosθ/|p|で計算できる | |
# この値は内積を利用し、|r||p|cosθ = r・p → |r|cosθ/|p| = r・p / |p|^2 で計算すると楽 | |
from math import sqrt | |
x1, y1, x2, y2 = map(int, raw_input().split()) | |
dx = x2 - x1 | |
dy = y2 - y1 | |
for i in xrange(input()): |
This file contains hidden or 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
#include<bits/stdc++.h> | |
using namespace std; | |
void solve(int n){ | |
vector<long long> a(n); | |
for(int i=0;i<n;i++) cin>>a[i]; | |
long long ans = 3000000; | |
for(int i=0;i<n;i++){ | |
for(int j=i+1;j<n;j++){ | |
ans = min(ans,abs(a[i]-a[j])); |