您的位置:首页 > 其它

POJ 简单搜索

2012-03-21 15:57 218 查看
简单搜索

深度优先搜索

poj2488,poj3083,poj3009,poj1321

广度优先搜索

poj2251,poj1426,poj3126,poj3087.poj3414

poj 1606

简单搜索技巧和剪枝

poj2531,poj1416,poj2676,poj1129

poj 2488

好恶心的题。。。应该用深搜的,我用的bfs,wa掉,改成dfs,还是wa。。。注意向八个方向扩展的顺序,保证输出结果按字典序排列。

int dir[8][2] = {{-2, -1},{-2, 1},{-1, -2},{-1, 2},{1, -2},{1, 2},{2, -1},{2, 1}};

贡献无数wa,T_T

poj 3083

求左优先和右优先的时候用dfs,注意顺序。

int Left[4][2] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
int Right[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

View Code

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>

using namespace std;

const int N = 50;
const int RAND = 100000;

bool sub
;
int mp

;
int n;

int solve() {
int i, j, t, sum = 0, res = 0;
memset(sub, 0, sizeof(sub));

for(i = 0; i < RAND; ++i) {
t = rand()%n;
sub[t] = !sub[t];
for(j = 0; j < n; ++j) {
if(sub[j] == sub[t]) {
sum -= mp[j][t];
} else {
sum += mp[j][t];
}
}
res = max(sum, res);
}
return res;
}

int main() {
//freopen("data.in", "r", stdin);

int i, j;
while(~scanf("%d", &n)) {
for(i = 0; i < n; ++i) {
for(j = 0; j < n; ++j) {
scanf("%d", &mp[i][j]);
}
}
printf("%d\n", solve());
}
return 0;
}


POJ 1129

图的着色问题。暴力回溯。详见:http://blog.csdn.net/suwei19870312/article/details/5282932
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: