TodaysJOI

JOI2007予選 問題1@C(-9)

気分でワンライナー。まあ127文字あるから厳密な意味でのワンライナーじゃないけど。当たり前だけど、-Wallとかでやると警告いっぱい出る。これより短くする方法あったら教えて。というか、GCC拡張の">?"が使えなかったのは本当痛い。 main(){int a,b,c,d,e,…

JOI2008本選 問題4@C++(-5)

典型的なDP。mins[i][j][m-1]=0;で0 /* TASKNO: 4 LANG: C++ NAME: Masaki Hara J */ #include <climits> #include <cstdio> #include <algorithm> #include <vector> using namespace std; typedef unsigned int uint; const int INIT_MAX=1000000000; int main(int argc,char* argv[]) { FILE* </vector></algorithm></cstdio></climits>…

JOI2008予選 問題6@C++(5)

最短距離の表を保持して、更新があるごとに隣接パスとの合計距離を再計算して更新キューに積む。 ダイクストラって言うんだっけ?いや違うかなあ。 対称テーブルはSTLには無いのかなあ。というわけで自分で実装。 あと、queueの辺りでpairが暴走してて困る。…

JOI2008予選 問題5@C++(7)

ビット演算の基本さえ知っていれば簡単。 #include <cstdio> #include <algorithm> #include <vector> using namespace std; int main(int argc,char* argv[]) { int r,c; scanf("%d %d",&r,&c); vector<int> nums(c); for(int i=0;i</int></vector></algorithm></cstdio>

JOI2008予選 問題4@C++(8)

まあ、そんなに難しくはない。stars_partのsortは不要な気がするが気にしない。 #include <cstdio> #include <algorithm> #include <vector> using namespace std; int main(int argc,char* argv[]) { int m,n; scanf("%d\n",&m); vector<pair<int,int> > stars_part(m); for(int i=0;i</pair<int,int></vector></algorithm></cstdio>

JOI2008予選 問題3@C++(12)

さっきのPerl版をC++で書き直した。今までこれは太郎と花子の配列を別で管理しないといけないと思ってたけど、さっきPerl版書いてる時に、他に方法ないかなと考えたら、一つの配列で一括して管理できることに気がついた。それと番兵法。playerの入れ替えで減…

JOI2008予選 問題3@Perl(13)

なんかPerlで書いてみたくなった。凄く読みづらいコードだが、変数名は比較的簡単なので、Perlにまつわるバッドノウハウを知っていればすぐ読める。しかし、PerlのRange Operator(".."のこと)は、全開区間なんだね。Pythonみたいに半開区間のほうが便利なの…

JOI2008予選 問題2@Python(14)

今度はPythonで書いてみた。 Perlなら文字列に文字列を含む個数を一発で数えるとかできるかもと思ったんだけどないっぽい。 Pythonは便利だけど、インクリメントが出来ないのが残念。 #!/usr/bin/python str = raw_input() joi = 0 ioi = 0 for i in xrange(…

JOI2008予選 問題1@C(15)

Hello, world!代わりにも使われる、有名な問題。(嘘 今回はCで書いてみた。 コードゴルフってほどではないけど、簡潔に書いてみた。番兵法。 #include <stdio.h> int coins[] = {500, 100, 50, 10, 5, 1, 0}; int main(int argc, char* argv[]) { int a,i=0,count=0; </stdio.h>…

JOI2006模擬試験1 問題5@C++(未完)(19)

boysの大きい方からデクリメントして素数判定するアルゴリズムなんだけど、入力5の残酷さが半端じゃない。 値のレンジが100000000000000000000くらいまであるのでunsigned long longでも足りないのでboys,girlsに分割して素数判定するはめに。 素数判定もや…

JOI2006模擬試験2 問題5@Python(24)

多倍長問題で非常に腹が立ったので腹いせにPythonで組む。 #!/usr/bin/python # -*- coding: utf-8 -*- import sys def combination(all, select): if(select < 0 or select > all): return 0 ret = 1 for i in xrange(select): ret=ret*(all-i)/(1+i) retur…

JOI2006模擬試験2 問題5@C++(25)

よくある数学の組合せ論の知識かと思って解いたらミスった。そりゃ、組合せ論的な規模の数って言ったら多倍長だもんなあ。つーかSTLに多倍長ってないのかよ使えねー!Javaならあるのに!Pythonなんか標準で多倍長だし!多倍長ライブラリのバグで何度も爆発(w…

JOI2006模擬試験2 問題4@C++(30)

s=2xy+x+yを(2s+1)=(2x+1)(2y+1)つまり奇数の積に変形できるので、一般の素数判定を利用できる。面積sはintの範囲内だがts=s*2+1はintではなくuintを使う必要があるというところでミスった。orzorz #include <cstdio> #include <algorithm> #include <vector> using namespace std; type</vector></algorithm></cstdio>…

JOI2008本選 問題3@C++(31)

去年は解けなかった問題。歯が立たなかったので復讐。upper_boundとlower_boundとequal_rangeとbinary_searchの使い方を覚えた。ところでこの関数群はset,multiset,map,multimapには独自で用意されているらしい。いいねえ。 /* TASKNO: 3 LANG: C++ NAME: Ma…

JOI2008本選 問題2@C++(38)

ソートの比較時に一致長を調べるっていうこの方法は割と変な方法だけど、好み。しかし苦労した。ところで厳密にこの方法はOKなのだろうか・・・。まあいいや。 /* TASKNO: 2 LANG: C++ NAME: Masaki Hara J */ #include <cstdio> #include <cstring> #include <algorithm> #include <vector> int </vector></algorithm></cstring></cstdio>…

JOI2008本選・・・の前に(44)

環境整備が面倒臭かった。CygwinじゃなくてDebian使ってるのでスクリプトの文字コードの変換とかするMakefileを書いた。やってることは改行コードのCRとcsh呼び出しの/usrプレフィックスと.exe拡張子の取り除き。 #!/bin/make TARGET = t1 SCRIPTS = compile…

JOI2008本選 問題1@C++(43)

昔のIDとか引っ張り出すの面倒なのでJで。 /* TASKNO: 1 LANG: C++ NAME: Masaki Hara J */ #include <cstdio> #include <algorithm> #include <vector> using namespace std; int main(int argc,char* argv[]) { FILE* in=fopen("input.txt","r"); FILE* out=fopen("output.txt","w"); </vector></algorithm></cstdio>…

先の記事についてお詫びと訂正(45)

眠いので適当に処理したのですが、vectorは要素数がわかっているのでpush_backより最初からnを指定したほうが効率がいいです。lizanの指摘により発覚。訂正は眠いのでしません。脳内補完よろしく。

JOI2006模擬試験2 問題3@C++ lizanの指摘により書き直し(46)

#include <cstdio> #include <algorithm> #include <vector> #include <string> using namespace std; class compare_query { public: bool operator()(const pair<string,int>& o1, const pair<string,int>& o2) const { const string& s1=o1.first; const string& s2=o2.first; if(s1.size()==s2.size()) return (s1</string,int></string,int></string></vector></algorithm></cstdio>

JOI2006模擬試験2 問題3@C++(51)

mapとかstringとかoperatorのoverload使うあたりあまり好きじゃないがこのアプローチが妥当 #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <string> #include <map> using namespace std; class ltstr { public: bool operator()(const string& s1, const string& s2</map></string></vector></algorithm></cstring></cstdio>…

JOI2006模擬試験2 問題2@C++(58)

予選レベルにして僕を手こずらせた問題があると思ったらなんだこれはwそうそう、個人的にswitchは嫌いなのでよろしく。 #include <cstdio> #include <algorithm> #include <vector> using namespace std; int main(int argc,char* argv[]) { int current; scanf("%d\n",&current); for(;</vector></algorithm></cstdio>…

JOI2006年模擬試験2 問題1@C++(65)

模擬試験1の問題5はまた今度。long longでも20桁の数全体はオーバーフローするという事実に気づかなかった(というより最大値を検証しなかった)僕の負けです。 今Pythonで調べたらlong longの最大値は9,223,372,036,854,775,807で、unsigned long longの最大…

JOI2006年模擬試験1 問題4@C++(85)

さりげ手こずった。予選レベルで手こずるとか駄目だ自分。 #include <cstdio> #include <algorithm> #include <set> #include <vector> using namespace std; int main(int argc,char* argv[]) { int n; scanf("%d\n",&n); vector<pair<int,int> > points(n); for(int i=0;i</pair<int,int></vector></set></algorithm></cstdio>

JOI2006年模擬試験1 問題3@C++(86)

最近の予選よりは模擬試験のほうが難しい気がする。 #include <cstdio> #include <algorithm> #include <vector> #include <queue> using namespace std; int decimal_digit(int a) { int ret=1; while(a) { ret=ret*10; a=a/10; } return ret; } int main(int argc,char* argv[]) { int n; sca</queue></vector></algorithm></cstdio>…

JOI2006年模擬試験1 問題2@C++(87)

#include <cstdio> #include <algorithm> #include <vector> using namespace std; int gcm(int a,int b) { int tmp; while(b) { tmp=a%b; a=b; b=tmp; } return a; } int main(int argc,char* argv[]) { int n; scanf("%d\n",&n); int max; if(n==2) { int a,b; scanf("%d %d\n",&a,&b)</vector></algorithm></cstdio>…

JOI2006年模擬試験1 問題1@C++(88)

zatorikuとかに負けてられないのでがんばってプログラミング練習する。 #include <cstdio> #include <algorithm> using namespace std; int main(int argc,char* argv[]) { int a,b,c; int count_all=0; int count_right=0; int count_less=0; int count_more=0; while(true) { </algorithm></cstdio>…