tjut 2822
来源:互联网 发布:欧洲为什么发达 知乎 编辑:程序博客网 时间:2024/06/03 22:41
#include <cstdio> #include <queue> #include <cstring> #include <iostream> #include <cstdlib> #include <algorithm> #include <vector> #include <map> #include <string> #include <set> #include <ctime> #include <cmath> #include <cctype> using namespace std; #define maxn 1005 #define LL long long int cas=1,T; char mapp[maxn][maxn]; int vis[maxn][maxn]; struct Node { char l; int x,y,time; friend bool operator < (const Node&a,const Node&b) {return a.time > b.time;} }; int n,m,startx,starty,endx,endy; int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; bool check(int x,int y) { if (x<1 || x>m || y<1 || y>n || vis[x][y]) return true; return false; } int bfs() { memset(vis,0,sizeof(vis)); priority_queue<Node> q; Node s,temp; s.x=startx; s.y=starty; s.time=0; vis[s.x][s.y]=1; q.push(s); while (!q.empty()) { s = q.top();q.pop(); if (s.x==endx && s.y==endy) return s.time; for (int i = 0;i<4;i++) { temp.x = s.x+dir[i][0]; temp.y = s.y+dir[i][1]; if (check(temp.x,temp.y)) continue; if (mapp[temp.x][temp.y]=='X') temp.time = s.time+0; else temp.time = s.time+1; vis[temp.x][temp.y]=1; q.push(temp); } } return -1; } int main() { while (scanf("%d%d",&m,&n)!=EOF && m && n) { for (int i = 1;i<=m;i++) scanf("%s",mapp[i]+1); scanf("%d%d",&startx,&starty); scanf("%d%d",&endx,&endy); int ans = bfs(); printf("%d\n",ans); } //freopen("in","r",stdin); //scanf("%d",&T); //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); return 0; }
0 0
- tjut 2822
- tjut 5289
- tjut 5288
- tjut 5294
- tjut 2586
- tjut 5296
- tjut 5297
- tjut 5299
- tjut 5384
- tjut 5387
- tjut 5386
- tjut 5381
- tjut 5400
- tjut 5399
- tjut 5396
- tjut 5398
- tjut 5412
- tjut 5410
- Linux服务-DHCP
- Spark Streaming kafka实现数据零丢失的几种方式
- Java的类(class)、包(package)和接口(interface)
- 看公司历史代码总结
- Spring
- tjut 2822
- C++中数字与字符串之间的转换
- POJ 3974 Palindrome(Manacher)
- 驱动开发用到的派遣函数序号(wdm.h)
- 扩展欧几里得(求逆元)
- cf XOR and Favorite Number
- mob 之 ShareSDK第三方分享
- 12.ATL中实现可连接对象和接收器
- multiple definition of 问题解决方法