This file contains 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
from fractions import Fraction | |
def in_out_heat(a,b,c,d): | |
A=4*(c-a)*(d-b) | |
B=b*(c-a)*Fraction(3,2)+a*(d-b)*Fraction(5,2) | |
if B*(A+B)>=0: | |
dU=Fraction(3,2)*(c*d-b*a) | |
dW=(b-d)*(a+c)*Fraction(1,2) | |
dQ=dU-dW | |
if B>=0 and A+B>=0: | |
return (dQ,0) |
This file contains 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
from sympy import * | |
def lattice_graph(H,W): | |
N=H*W | |
G=[[] for i in range(N)] | |
for i in range(H-1): | |
for j in range(W): | |
x=i*W+j | |
y=(i+1)*W+j | |
G[x].append(y) | |
G[y].append(x) |
This file contains 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
from scipy.optimize import linprog | |
# vim: set fileencoding=utf-8 | |
K=3 | |
N=K*K | |
c = [-1 for i in range(N**3)] | |
A = [[0 for i in range(N*N*N)] for i in range(4*N*N)] | |
b = [1 for i in range(4*N*N)] | |
for i in range(N): | |
for j in range(N): | |
for k in range(N): |
This file contains 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
''' | |
https://twitter.com/kumiromilk/status/707437861881180160 | |
Javaの講義、試験が「自作関数を作り記述しなさい」って問題だったから | |
「ズン」「ドコ」のいずれかをランダムで出力し続けて「ズン」「ズン」「ズン」「ズン」「ドコ」の配列が出たら「キ・ヨ・シ!」って出力した後終了って関数作ったら満点で単位貰ってた | |
''' | |
import random | |
from collections import deque | |
deq=deque([]) | |
while(True): |
This file contains 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
''' | |
出典 | |
https://twitter.com/jajaaankara_kdb/status/1446313136928083972 | |
''' | |
MAX_N=10**4 | |
isPrime=[True for i in range(MAX_N+1)] | |
isPrime[0]=False;isPrime[1]=False | |
for i in range(MAX_N+1): | |
if isPrime[i]: | |
for j in range(2*i,MAX_N+1,i): |
This file contains 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
mex=1 | |
while(True): | |
print(mex) | |
X=mex | |
S={X} | |
while(X>1): | |
if X%2==0: | |
X//=2 | |
else: | |
X=3*X+1 |
This file contains 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
N,Q=map(int,input().split()) | |
A=[int(i) for i in input().split()] | |
G=[[0 for j in range(N)]for i in range(N)] | |
for _ in range(Q): | |
x,y=map(int,input().split()) | |
G[x-1][y-1]=1 | |
G[y-1][x-1]=1 | |
S=sum(A) | |
X=[[] for i in range(S+1)] | |
isok=False |
This file contains 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
mod=10**9+7 | |
def sum_len(l,r): | |
if r-l==1: | |
return (len(str(l)))%mod | |
if l%10!=0: | |
return (len(str(l))+sum_len(l+1,r))%mod | |
if r%10!=0: | |
return (len(str(r-1))+sum_len(l,r-1))%mod | |
assert l%10==0 | |
assert r%10==0 |
This file contains 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
''' | |
FFTライブラリの詳細!! | |
https://github.com/shakayami/ACL-for-python | |
''' | |
class FFT(): | |
def primitive_root_constexpr(self,m): | |
if m==2:return 1 | |
if m==167772161:return 3 | |
if m==469762049:return 3 |
This file contains 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 random | |
from collections import defaultdict | |
from fractions import Fraction | |
import itertools | |
D=list("おちんまうこ") | |
FACES={"う":500,"ま":500,"ち":500,"ん":50,"こ":100,"お":300} | |
WORDS={"うんち":1000,"うんこ":1000,"まんこ":1000,"おまんこ":5000,"ちんこ":1000,"ちんちん":3000,"おちんちん":10000} | |
TRIPILES={"う":2,"ま":2,"ち":2,"ん":-3,"こ":Fraction(3,2),"お":Fraction(3,2)} | |
def todict(S): | |
SS=defaultdict(int) |
NewerOlder