2012-03-31から1日間の記事一覧

POJ_1979 Red and Black

問題 '@'から縦横に進んでいけるマスの個数をもとめよ 解法 深さ優先探索をしてもとめる #include <cstdio> #include <algorithm> using namespace std; const int MAX_HW = 20; char a[MAX_HW + 2][MAX_HW + 2]; int H, W, sx, sy; const int dx[] = { -1, 0, 0, 1}; const int</algorithm></cstdio>…

AOJ_1141 POJ_3006 ディリクレの算術級数定理

問題(AOJ) 問題(POJ) 解法 エラトステネスの篩をつかうだけ。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; char prime[1000000]; int a, d, n; int main(){ memset(prime, sizeof(prime), 0); prime[1] = 1; for(int i = 2; i <= 1000; i++){ if(pr</algorithm></cstring></cstdio>…

POJ_3723 Conscription

問題 解法 蟻本を参考にした。 最小全域木を求めればいいみたい。 連結成分ごとにプリム法を行うというやりかたをした。 #include <cstdio> #include <algorithm> #include <vector> #include <queue> using namespace std; typedef pair<int, int> P; //最小コスト、位置 const int INF = 1 << 30; const</int,></queue></vector></algorithm></cstdio>…