[uva11OPEN]玉米田迷宫Corn Maze(广搜bfs)
Posted phemiku
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[uva11OPEN]玉米田迷宫Corn Maze(广搜bfs)相关的知识,希望对你有一定的参考价值。
第一次做MLE了…第二次WA了5个点,其实就是一个判断错了…QAQ总的来说…是个水题/板子题(逃
#include<bits/stdc++.h> using namespace std; #define For(i,l,r) for(register int i=l; i<r; i++) int n,m; int d[4][2] = 0, 1, 0, -1, 1, 0, -1, 0 ; bool bj,vis[301][301]; char ch[301][301]; struct cs int x1,y1,x2,y2; bool p; chs[35]; struct node int x, y, t; q[90001]; inline bool check(int x, int y) return x >= 0 && y >= 0 && x < n && y < m && vis[x][y] == 0; int main() int sx,sy,ex,ey; string s; scanf("%d%d",&n,&m); For(i,0,n) cin>>s; For(j,0,m) if(s[j] == ‘=‘)ex = i, ey = j; else if(s[j] == ‘#‘)vis[i][j]=1; else if(s[j] == ‘@‘)sx = i, sy = j; else if(s[j] >= ‘A‘ && s[j] <= ‘Z‘) int c = s[j]-‘A‘; ch[i][j] = s[j]; if (chs[c].p == 1)chs[c].x2 = i, chs[c].y2 = j; //就是这儿的判断!555查了一晚上_(:3/)__ else chs[c].x1 = i, chs[c].y1 = j, chs[c].p = 1; int head = 0, tail = 1; q[tail].x = sx, q[tail].y = sy; vis[sx][sy] = 1; while(head < tail) head++; int xn = q[head].x, yn = q[head].y; For(i,0,4) int dx = d[i][0] + xn; int dy = d[i][1] + yn; if(check(dx,dy)) vis[dx][dy] = 1; if(ch[dx][dy] >= ‘A‘ && ch[dx][dy] <= ‘Z‘) int c = ch[dx][dy] - ‘A‘; if (dx == chs[c].x1 && dy == chs[c].y1) dx = chs[c].x2, dy = chs[c].y2; else dx = chs[c].x1, dy = chs[c].y1; q[++tail].x = dx; q[tail].y = dy; q[tail].t = q[head].t + 1; if(dx == ex && dy == ey) cout << q[tail].t; return 0;
以上是关于[uva11OPEN]玉米田迷宫Corn Maze(广搜bfs)的主要内容,如果未能解决你的问题,请参考以下文章
洛谷 P1825 [USACO11OPEN]玉米田迷宫Corn Maze
luogu P1825 [USACO11OPEN]玉米田迷宫Corn Maze 题解