2014-10-01から1ヶ月間の記事一覧

SRM 453 div1 easy

SRM

勝敗を全列挙する #coding: utf-8 def solve(i,j,s,P,N,M): ret = 0 if i == j: if i == N-1: k = sorted(s) k.reverse() ss = tuple(k) if ss[0] == M: if ss not in P: P.add(ss) ret = 1 else: ret = solve(0,j+1,s,P,N,M) else: # i vs j s[j] += 2 ret …

SRM 452 div1 easy

SRM

Greedy 証明は ABAB CDCD ABAB CDCDみたいな塗り分けをするとできる #coding: utf-8 class NotTwo: def maxStones(self, width, height): a = [[0 for i in range(width+2)] for j in range(height+2)] ans = 0 for c in range(2,width+2): for r in range(2…

SRM 449d1 easy

SRM

あり得るすべての辺の長さの組合せを列挙して最大の面積の三角形を求める. #coding: utf-8 import math EPS = 0.0001 def pitagoras(x): a = 0 ret = [] while a ** 2 <= x / 2 + 1: r = x - a ** 2 b = math.sqrt(r) b += EPS c = int(b) if c ** 2 == r: …

SRM 448 div1 easy

SRM

期待値計算 #coding: utf-8 # 1 2 3 4 5 6 7 8 9 T cs = [0, 4,4,4,4,4,4,4,4,4,16] scr= [0,11,2,3,4,5,6,7,8,9,10] def solve(v,s): if s >= 21: return 0.0 else: a = sum(v) e = 0.0 for i in range(1,11): if v[i] > 0: n = v[i] v[i] -= 1 e += (solve…

SRM 447 div1 easy

SRM

実装 # coding: utf-8 d = ((-2,-1),(-2,1),(-1,-2),(-1,2),(1,-2),(1,2),(2,-1),(2,1)) blocked = [[False for i in range(8)] for j in range(8)] def calc(y,x): if 0 <= y < 8 and 0 <= x < 8 and (not blocked[y][x]): ret = 0 for dy,dx in d: ny,nx =…

SRM 446 div1 easy

他の面に出たときは,今までいた面の反対側から出てくると考えると,1面だけ考えればよい. #coding: utf-8 cube = (('RED','BLUE','RED'), ('BLUE','GREEN','BLUE'), ('RED','BLUE','RED')) direction = ((0,1),(1,0),(0,-1),(-1,0)) class CubeWalking: de…

SRM 636 div 1

SRM

デバッグ用のprintfを消し忘れていたせいでTLEした.つらすぎ #include <cstdio> #include <algorithm> #include <string> #include <vector> using namespace std; int choco[55][55]; int sum[55][55]; class ChocolateDividingEasy{ public: int h,w; int S(int a, int b, int x, int y){ ret</vector></string></algorithm></cstdio>…

444 div1 easy

SRM

TLEしたので枝刈りしたら通った # coding: utf-8 def unfold(grid, limit, i, j, n): if i - n + 1 < 0: return False if j + n > len(grid)-1: return False tri = 0 for h in range(n): if grid[j+h][i+1] == '#': return False if grid[j+h][i-h] != '/':…

SRM 433 div1 easy

SRM

pythonで解いた.C++より気軽に書ける気がする # coding: utf-8 def distance2(p, q): return (p[0]-q[0])**2 + (p[1]-q[1])**2 def isinCircle(c,r,p): if distance2(c,p) < r**2: return True return False class CirclesCountry: def leastBorders(self, …