2010-11-01から1ヶ月間の記事一覧

SRM489

Easy (300) 246.48 Medium (500) 207.95 Hard (1000) 0 Challenge +50 -25 結果 1831 → 1896500を2回再投稿したのとチャレンジで点を稼げなかったのが残念だが、まずまずの結果。

SRM488 Div1 Medium(500) TheBoringStoreDivOne

TheBoringStoreDivOneu,v∈Σ+, x∈Σ*として、A=ux, B=u, C=v, D=xvと書ける。uとvが影響し合うことはないので、各xについて最も長いuを覚えておく。 #include <string> #include <map> using namespace std; bool cmp( string a, string b ) { return a.length() < b.length</map></string>…

SRM488 Div2 Hard(1000) TheBoringGameDivTwo

試合の進み方が9通りあって、それぞれの回数をx1〜x9とすると、 x1(0,0,0,+1,0,+1)+x2(0,+1,0,0,0,+1)+x3(-1,+1,0,+1,+1,0)+x4(0,+1,-1,+1,+1,0)+x5(+1,0,0,0,0,+1)+x6(0,0,+1,0,0,+1)+x7(0,+1,+1,0,+1,+1)+x8(+1,0,0,+1,+1,+1)+x9(0,+1,0,+1,+2,0)=(scoreJ…

SRM488 Div2 Medium(500) TheBoringStoreDivTwo

TheBoringStoreDivTwo文字列長が短いのでO(n8)でも間に合う。 #include <string> using namespace std; class TheBoringStoreDivTwo{public: string find( string J, string B ) { int x = (int)J.length(); int y = (int)B.length(); string ans = ""; for ( int i=</string>…

SRM488 Div2 Easy(250) TheBoredomDivTwo

TheBoredomDivTwo class TheBoredomDivTwo{public: int find( int n, int m, int j, int b ) { return n + (j>n) + (b>n); }};

SRM488 Div1 Easy(250) TheBoredomDivOne

TheBoredomDivOne動的計画法。退屈ではない人がi人の場合に全員を退屈にする時間の期待値をbi、その時に退屈ではない人をj人選ぶ確率をpjとすると、bi = p0 bi + p1 bi-1 + p2 bi-2 + 1。変形して、bi = ( p1 bi-1 + p2 bi-2 + 1 ) / (1-p0)。 #include <vector> usi</vector>…

SRM488

Easy (250) 145.35 Medium (500) 0 Hard (1000) 0 Challenge 0 結果 1797 → 1831145点で145位だった。

SRM487 Div1 Easy(250), Div2 Medium(500) BunnyComputer

BunnyComputerk+1で割った余りが等しい時刻しか干渉しないので分けて考える。例の問題なら、3,1,2と1,5,6と4,9。グループの要素数が偶数ならすべてのpreferenceが得られる。奇数ならば奇数番目のpreferenceのうちどれか1つが得られない。 #include <vector> #includ</vector>…

SRM487

旅行中のため不参加。

Codeforces School Team Contest #2 H. Phone Number

Phone Number動的計画法。i番目の数字がjであるときi番目以降に何通りの電話番号があるかを記憶しておく。Masha自身の番号が生成可能なら-1。 d = [int(x) for x in raw_input()] n = len(d) T = [[0]*10 for x in range(n)] T[n-1] = [1]*10 for i in range…

Codeforces School Team Contest #2 E. Anfisa the Monkey

Anfisa the Monkey全てを同じ長さ、もしくは長さの差が1になるように切るのが最善。 k,a,b = map(int,raw_input().split()) t = raw_input() n = len(t) l = n/k if a<=l<=b-1 or a<=l<=b and n-k*l==0: for i in range(k*(l+1)-n): print t[:l] t = t[l:] …

Codeforces School Team Contest #2 D. Hyperdrive

Hyperdrive惑星を2つ経由する距離の最小値の半分。平方根の計算が重いので、なるべく減らすようにしたら通った。 #include <iostream> #include <vector> #include <cmath> using namespace std; double dist( vector<int> a, vector<int> b ) { return sqrt( pow((double)a[0]-b[0],2) + pow((</int></int></cmath></vector></iostream>…

Codeforces School Team Contest #2 C. Holidays

Holidays n,m = map(int,raw_input().split()) f = [0]*(n+1) for i in range(m): a,b = map(int,raw_input().split()) for j in range(a,b+1): f[j] += 1 for i in range(1,n+1): if f[i]!=1: print i, f[i] exit() print "OK"

Codeforces School Team Contest #2 B. Cola

ColaDPにするまでもない。 #include <iostream> using namespace std; int main() { int n, a, b, c; cin >> n >> a >> b >> c; int r = 0; for ( int i=0; i<=a; i+=2 ) for ( int j=0; j<=c; j++ ) { int k = n - i/2 - j*2; if ( 0 <= k && k <= b ) r++; } cout <<</iostream>…

SRM487 Div2 Hard(900) BunnyConverter

BunnyConverter逆から辿ればxが一意に定まる。900にしても簡単では? class BunnyConverter{public: int getMinimum( int n, int z, int start, int goal ) { int z3 = (long long)z * z % n * z % n; long long t = goal; for ( int i=0; i

SRM487 Div2 Easy(250) BunnyExamAfter

BunnyExamAfter #include <string> using namespace std; class BunnyExamAfter{public: int getMaximum( string black, string gray, string white ) { int N = (int)black.size(); int ans = 0; for ( int i=0; i</string>

SRM487 Div1 Medium(550) BunnyExam

BunnyExam -1となるのは、k=1で長さが2以上の場合、k=2でリンクの両端の偶奇が異なる場合、リンクの両端が接している場合。あとは接している答えが異なるようなリンクの割り当てが出来ない場合。ただしリンクの両眼が接しているリンクの端は高々4つなので、…

Codeforces School Team Contest #2 A. Indian Summer

Indian Summer import sys print len(set(sys.stdin))-1

Codeforces Beta Round #39 B. Repaintings

Repaintings n,m=map(int,raw_input().split()) x=input()-1 print max(n+m-4*x-2,1) if min(n,m)>2*x else 0

Codeforces Beta Round #39 A. Find Color

Find Color x,y = map(int,raw_input().split()) r = int((x*x+y*y)**0.5) print "black" if x*x+y*y==r*r or (r+(x>0)+(y>0))%2==0 else "white"

SRM486 Div2 Hard(1000) CrazyLine

CrazyLine中央値xより低い生徒と高い生徒を交互に並べるとそれぞれの生徒のcrazinessへの寄与は2abs(heights[i]-x)。ただし両端の生徒はこれより小さいので、中央値付近の生徒を両端に置く。生徒数が奇数の場合は選び方が2通りあるので、よりcrazinessの大…