思路:
bfs,用状压表示走过的区域,然后和x1,y1,x2,y2构成所有的状态,然后标记一下就可以了
代码:
#pragma GCC optimize(2)#pragma GCC optimize(3)#pragma GCC optimize(4)#includeusing namespace std;#define fi first#define se second#define pi acos(-1.0)#define LL long long//#define mp make_pair#define pb push_back#define ls rt<<1, l, m#define rs rt<<1|1, m+1, r#define ULL unsigned LL#define pll pair #define pii pair #define piii pair #define mem(a, b) memset(a, b, sizeof(a))#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);//head bool vis[(1<<16) + 10][5][5][5][5];int dir[4][2] = { 0, 1, 1, 0, 0, -1, -1, 0};char s[10][10];int n, m;struct node { int x1, y1, x2, y2, dis, st;};int get(int x, int y) { return (x-1)*m + y - 1;}int bfs() { queue q; int st = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if(s[i][j] == 'S' || s[i][j] == 'X') st |= 1<