2012-01-01から1年間の記事一覧

AOJ 0212 Highway Express Bus

これは良問だと思った。 これを機にダイクストラ法の理解が一層深まった気がする。 解説 まず、下のコードではdpテーブルはdとおいて、d[0][i]に普通のダイクストラ法をやっていく。その後にmin(~,~)で割引券を使った時と使ってない時を判定して、最短経路を…

POJ 2707 Copier Reduction

解説 サンプルセット見た感じだと、多分縮小の問題だと思うのでそのまま実装 #include <iostream> #include <cstdio> #include <cmath> using namespace std; int f(double a, double b){ return (int)(b/a*100); } int main(){ int l,r; double a,b,c,d; while(cin >> a >> b >> c >></cmath></cstdio></iostream>…

今日

今日は全然PKUしなかったし全然頭を使わなかったので反省。学校の課題をするのと本を読んでいました。ゼロから学ぶベクトル解析 (ゼロから学ぶシリーズ)作者: 西野友年出版社/メーカー: 講談社発売日: 2002/04/26メディア: 単行本(ソフトカバー)購入: 1人 …

GCの本

ガベージコレクションのアルゴリズムと実装作者: 中村成洋,相川光,竹内郁雄出版社/メーカー: 秀和システム発売日: 2010/03/17メディア: 単行本購入: 25人 クリック: 810回この商品を含むブログ (94件) を見るまだちょっとしか読んでないのですが、GCアルゴリ…

POJ 2656 Unhappy Jinjin

下にコードが書いてあるなーとか思ってたら答えだったので萎えぽよ〜 a,b,d,v,i;main(n){while(scanf("%d",&n),n){v=-1;for(i=1;i<=n;i++){scanf("%d%d",&a,&b);if(a+b>v)v=a+b,d=i;}if(v<=8)puts("0");else printf("%d\n",d);}}

POJ 2578 Keep on Truckin'

short codingっぽいようななにか。もっと工夫できると思うけどお馬鹿な脳をしているので全く思いつかない。 i,h[3];main(){scanf("%d%d%d",h+0,h+1,h+2);for(;i<3;i++){if(h[i]<168){printf("CRASH %d\n",h[i]);break;}else if(i==2)puts("NO CRASH");}}

POJ 2521 How much did the businessman lose

解説 いくら損したか(問題分全然読んでないので適当) main(n,m,p,c){while(scanf("%d%d%d%d",&n,&m,&p,&c),n)printf("%d\n",n-m+p);} scanfとても面白い。%*[フォーマット指定子]で引数を取らない入力になるとは...

POJ 2390 Bank Interest

解説 Hint見たらそのまま実装すればいい。 #include <iostream> using namespace std; int main(){ int c; double n,m; cin >> n >> m >> c; while(c--) m *= 1+(n/100); cout << (int)m << endl; }</iostream>

POJ 2388 Who's in the Middle

解説 真ん中にいる人を求めるだけ。 #include <iostream> #include <algorithm> #include <vector> using namespace std; int main(){ int n,a; vector<int> v; cin >> n; for(int i = 0; i < n; i++){ cin >> a; v.push_back(a); } sort(v.begin(),v.end()); cout << v[n/2] << endl; }</int></vector></algorithm></iostream>

POJ 1067 取石子游戏

解説 ゲームにっき(仮) |PKU 1067 - 取石子游戏ここを見て解きました...。もう答えのようなものなので無念。 #include <iostream> #include <cmath> #include <algorithm> using namespace std; int main(){ int a,b; double r = (1+sqrt(5.0))/2; while(cin>>a>>b){ if(a>b) swap(a,b); </algorithm></cmath></iostream>…

POJ 3617 Best Cow Line

解説 蟻本に書いてある。が、80文字で改行とfrontとbackが同じことも考えるということを忘れていて5回ぐらいWAなりPEなり出された。 #include <iostream> #include <cstdio> #include <vector> using namespace std; int main(){ int n,c=0; char a; vector<char> cv; cin >> n; for(int i = </char></vector></cstdio></iostream>…

POJ 2386 Lake Counting

解説 特になし。蟻本に書いてある。 #include <iostream> using namespace std; int n,m,c; char map[102][102]; void dfs(int x, int y){ map[x][y] = '.'; for(int i = -1; i <= 1; i++){ for(int j = -1; j <= 1; j++){ int nx = x + i, ny = y + j; if(0 <= nx && </iostream>…

POJ 2456 Aggressive cows

解説 蟻本に書いてある。 #include <iostream> #include <algorithm> #include <vector> using namespace std; const int INF = 1 << 29; int n,m,a; vector<int> x; bool C(int d){ int last = 0; for(int i = 1; i < m; i++){ int crt = last + 1; while(crt < n && x[crt] - x[last] < d) cr</int></vector></algorithm></iostream>…

POJ 1064 Cable master

解説 蟻本に解法が載ってある。 二部探索まだまだ身についてない。 #include <iostream> #include <cmath> using namespace std; const int INF = 1 << 29; int n,k; double l[10001]; bool C(double x){ int num = 0; for(int i = 0; i < n; i++) num += (int)(l[i] / x); re</cmath></iostream>…

POJ 1852 Ants

最初やったら何故かG++でcompileされててさらにTLEくらって訳が分からなかった。 #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int c,n,l,a; cin >> c; while(c--){ int minT=0, maxT=0; vector<int> v; cin >> l >> n; for(int i = 0; i < n</int></algorithm></vector></iostream>…

POJ 1046 Color Me Less

問題文要約 そのまま実装。int型でsqrtしなくてもオーバーフローしないかなーとか思ってたけどAcceptできたのでよしとしよう。 #include <cstdio> #include <algorithm> #include <vector> using namespace std; class color{ public: int r,g,b,d; }; bool LessColor(const color& l, c</vector></algorithm></cstdio>…

POJ 1005 I Think I Need a Houseboat

問題文要約 図のような島があり、1年で50平方マイルずつ中心から半円で侵食していく。座標が与えられるので、その座標の位置が侵食される年数を出力せよ。 #include <cmath> #include <cstdio> using namespace std; const double PI = acos(-1); int main(){ int n,year; d</cstdio></cmath>…

POJ 1004 Financial Management

#include <iostream> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; int main(){ double a,s; rep(i,12){ cin>>a; s += a; } cout<<'$'<</iostream>

POJ 1003 Hangover

#include <iostream> using namespace std; int main(){ double n,i,s; while(cin>>n,n){ i = 2, s = 1/i; while(s < n){ i++; s += 1/i; } cout<<--i<<" card(s)"<</iostream>

POJ 1000 A+B Problem

a;main(b){scanf("%d%d",&a,&b);printf("%d\n",a+b);} short codingみたいなものをやったが、これは全然short codingしてないのでNG

hello

#include<stdio.h> int main(){ printf("Hello World!\n"); return 0; }</stdio.h>