2011-03-01から1ヶ月間の記事一覧

SRM403 div2 hard

丸写し上等! ・・・・・・・解けへんかった #include <algorithm> #include <utility> #include <vector> #define INF (1<<29) using namespace std; class TheSumOfLuckyNumbers { public: int DP[1000000+1]; bool isLucky(int n) { while(0<n) if(n%10!=4 && n%10!=7) return false; else n/=10; return true; } vector <int> sum(int n) { …</n)></vector></utility></algorithm>

SRM347 div2 hard

巡回セールスマン+ビットで全探索なんだけど "~mask"を"(1 #include <sstream> #include <string> #include <vector> using namespace std; class TaxiManager { public: int dist[50][50]; int DP[12][(1<<12)]; int cost[(1<<12)]; int schedule(vector<string> roads, vector<string> _customers) </string></string></vector></string></sstream>…

SRM411 div2 hard

最大でも200*200程度の大きさでしかないので 座標を全てメモリにとってシュミレーション。 #include <vector> #include <queue> #define OFFSET 100 using namespace std; class HoleCakeCuts { public: int cake[201][201]; int cutTheCake(int cakeLength, int holeLength</queue></vector>…

SRM309 div2 hard

候補になりそうな所を全部試したら通った #include <algorithm> #include <climits> #include <sstream> #include <string> #include <vector> typedef long long LL; using namespace std; LL ABS(LL n) { return (0<=n) ? n : -n; } class SynchronizingGuideposts { public: LL minCost(vector<string> _guidepo</string></vector></string></sstream></climits></algorithm>…

SRM434 div2 hard

多倍長計算が必要、最初はdoubleでやろうとしたけど通らなかったので(解説見たので)多倍長に切り替えた。5時間ぐらいかかったんちゃうかな。 #include <string> #include <functional> #include <algorithm> #include <vector> using namespace std; int c2i(char c) { return (c<='9') ? c-'0' :</vector></algorithm></functional></string>…

SRM326 div2 hard

水面の高さを1ずつ上げていってBFSすると簡単に書けた #include <queue> #include <vector> #include <string> using namespace std; class PoolFiller { public: int BFS(vector<string> pool) { int h=pool.size(),w=pool[0].size(); int r=0; int mv[4][2]={{0,-1},{0,1},{-1,0},{1,0}};</string></string></vector></queue>…

SRM464 div2 hard

拡張幅優先探索って言うのかな。知らないけど。 prob[y][x][visited]でBFSすると通る。 ビット演算で間違えた。 #include <string> #include <queue> #include <vector> using namespace std; class Q { public: int x,y,visited; double safe; }; class ColorfulMazeTwo { public: </vector></queue></string>…

SRM330 div2 hard

久しぶりにパズル的な問題が出たので手も足も出なかった (前半分 + 前半分をひっくり返したもの)もしくは (前半分+1 + 前半分+1をひっくり返したもの)が答え #include <algorithm> #include <string> #include <vector> using namespace std; class NextPalindromicNumber { p</vector></string></algorithm>…

SRM389 div2 hard

全探索で間に合う、難しさの計算も2^6通り全て試してよい #include <string> #include <sstream> #include <vector> using namespace std; class GuitarChords { public: vector<int> strings; vector<int> chord; vector<int> play; int sN,cN,ans,all; int s2i(string s) { if(s=="A") return 0; if</int></int></int></vector></sstream></string>…

SRM384 div2 hard

また落とした。もう眠いので解説は TopCoder Statistics ここ読んでください #include <cstdio> #include <string> #include <algorithm> using namespace std; class PowerGame { public: string winner(int size0, int size1) { int DP[10005]; for(int num=0;num<10005;num++) { if(n</algorithm></string></cstdio>…

合宿が中止になったみたいです。そもそも関係ないけど。

SRM329 div2 hard

日付が代わりそうなんだけど… メモ化再起で書いてしまった。通ったからいいけど何とかしないと。 汚いのであんまり参考にならないと思う。 #include <string> #include <sstream> #include <vector> #include <map> using namespace std; class ProbabilisticTranslator { public: int n; m</map></vector></sstream></string>…

SRM353 div2 hard

メモ化再起で通ると思ったらEPSでつまずいた 実数型の統合付き比較は "x #include <cstring> #include <cmath> #include <sstream> #include <string> #include <vector> #define EPS 1e-9 using namespace std; class PlatformJumper { public: int n,v,g; vector<int> x; vector<int> y; vector<int> coin; int cach</int></int></int></vector></string></sstream></cmath></cstring>…

SRM352 div2 hard

x+yP>=minimum (xはどの馬も勝たなかったときに入ってくるお金の期待値 yはどの馬かが勝ったときに出て行くお金の期待値(マイナスになる)) を変形して P=(minimum-x)y (ただしy==0かつminimum #include <vector> #define EPS 1e-16 using namespace std; class R</vector>…

SRM314 div2 hard

方針が間違ってて何度もTLEした。 cache[すでに使ったフェンス(bit)]でメモれば一発。 #include <cmath> #include <vector> #include <algorithm> using namespace std; class GrasslandFencer { public: vector<int> fences; double cache[(1<<16)]; int n; double heron(int _a,int _b,int</int></algorithm></vector></cmath>…

SRM363 div2 hard

メモ化再起で書いた。n=15に脊髄反射でbitDP的な感じ。 cache[何回目][すでにインストールされているもの(bit)]でメモ化。 #include <string> #include <sstream> #include <vector> using namespace std; class CrazyComponents { public: double cache[55][(1<<15)]; vector<int> require</int></vector></sstream></string>…

SRM366 div2 hard

最初に選ぶ所を決めたら、1回選ぶごとに右と左に分けて考えられる ターン制の問題は実装が多くなるから嫌い たぶんDPでもできる。 ていうかこのコードはちょっと頭が悪いので計算量が2倍になっている #include <cstring> #include <cstdio> #include <utility> #include <vector> using namespa</vector></utility></cstdio></cstring>…

SRM300 div2 hard

列車を動かしても本質的な(円にそって回すと)順番は変わらないので 貪欲に動かせる列車の中で一番番号の若いものから動かす ちなみにこれがdiv2hard50問め、あと50問 #include <string> using namespace std; class CircleOrder { public: string firstOrder(s</string>…

SRM315 div2 hard

1時間分からなかったので解説見てしまった。 悔しいけどエジソンが言ってる言葉もあるし次頑張る。 ソースコードは解説の丸パクなのでそっちを見てください。 TopCoder Statistics シュミレーションを早めに見切れば思いついたかもなあ・・・

SRM439 div2 hard

swapは一番最初にすれば全部試してしまえば良いというのに気づけば一発 一回の操作ごとに前1つか、後ろ1か、前後ろ1つずつ考えなくても良くなる #include <cstring> #include <string> using namespace std; class PalindromeFactory { public: string source[50][50]; int c</string></cstring>…

SRM425 div2 hard

全探索なんだけど、しんどすぎる。 #include <algorithm> #include <string> #include <vector> #include <cmath> #include <set> using namespace std; class PiecesMover { public: int n; vector<int> pos; int DFS(set<int> se,vector<int> p) { //printf("p.size()=%d\n",p.size()); int r=(1<<28); if(p.size(</int></int></int></set></cmath></vector></string></algorithm>…

SRM451 div2 hard

BFSやるだけなんだけど、何回かTLEした。詳細はソース内のコメントでどうぞ #include <cmath> #include <string> #include <queue> #include <vector> using namespace std; class Q { public: int y,x,c; }; class PizzaDelivery { public: int cost[50][50]; int deliverAll(vector<string> terra</string></vector></queue></string></cmath>…

SRM429 div2 hard

トポロジカルと間違えて1時間以上かかった。 ただのDFSーーでは説明になってないか とりあえず条件を全て満たすものを一つ見つける そのあと最小化するために候補全てのgcd(最大公約数)で割る #include <cstring> #include <string> #include <vector> using namespace std; typedef</vector></string></cstring>…

SRM421 div2 hard

親切に0から9まで載っていたから助かった っていうかこれないと無理 #include <string> #include <vector> using namespace std; class FloorIndicator { public: vector<int> canDig(vector<string> dig,vector<string> ind,int pos) { vector<int> r; for(int n=0;n<10;n++) { bool b=true; for(int</int></string></string></int></vector></string>…

SRM449 div2 hard

DPだと思って頑張ったのに分からないから、解説見たら全探索だった #include <algorithm> #include <cmath> #include <cstdio> #include <vector> #define OFFSET 3 using namespace std; class HexagonalBattlefieldEasy { public: int field[8][8]; int DFS(int pos) { int x=pos%7,y=pos/7,r</vector></cstdio></cmath></algorithm>…

AOJ 0023

ウォーミングアップその2。2つの円の位置関係は、まあ検索したら出てきます。 誤差が気になったけど通った。 #include <cmath> #include <cstdio> #include <algorithm> int main() { int N; scanf("%d",&N); for(int i=0;i</algorithm></cstdio></cmath>

AOJ 0044

やるだけ、頭のウォーミングアップと思ってやった これを読んでも分からない人は「エラストテネスの篩」で検索 #include <cstdio> #include <cstring> bool isPrime[100000]; int main() { for(int i=0;i<100000;i++) isPrime[i]=true; isPrime[0]=isPrime[1]=false; for(int </cstring></cstdio>…