例题7-9 万圣节后的早晨(The Morning after Halloween, Japan 2007, UVa1601)

思路:同为bfs求解最少步数,问题在于状态如何更好地枚举。
无法开256^3的数组,利用题中2*2格中必有*的条件,改矩阵图为存边的图,点则变为144个,可存数组。
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <utility>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cctype>
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define IN() freopen("in.txt", "r", stdin)
#define OUT() freopen("out.txt", "w", stdout)
#define LL long long
#define mod 1000000007
#define INF 1000000007
#define eps 1e-5
#define PI 3.1415926535898
using namespace std;
//-------------------------CHC------------------------------//
const int maxw = 16 + 5;
const int maxn = 144 + 5;
const int dx[] = { 1, -1, 0, 0, 0 };
const int dy[] = { 0, 0, 1, -1, 0 };
char G[maxw][maxw];
int newG[maxn][5], degree[maxn];
int w, h, n;
int s[3], t[3];
struct Node {
	int a, b, c;
	Node(int a, int b, int c): a(a), b(b), c(c) { }
};
int d[maxn][maxn][maxn];

bool conflict(int a, int b, int na, int nb) { return na == nb || (a == nb) && (b == na); }

int bfs() {
	CLEAR(d, -1);
	queue<Node> q;
	q.push(Node(s[0], s[1], s[2]));
	d[s[0]][s[1]][s[2]] = 0;
	
	while (q.size()) {
		Node u = q.front(); q.pop();
		if (u.a == t[0] && u.b == t
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值