hnu 1242 Rescue
来源:互联网 发布:手机后期ps软件 编辑:程序博客网 时间:2024/05/01 20:36
hnu 1242 Rescue
题意就是Angel困在监狱中 有朋友去救她 遇到保卫 就Kill且时间+1 走一步时间+1
求最后所需最少的时间 另外还有可能救不出来
代码如下:
#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#include <queue>#define eps 1e-8#define op operator#define MOD 10009#define MAXN 100100#define FOR(i,a,b) for(int i=a;i<=b;i++)#define FOV(i,a,b) for(int i=a;i>=b;i--)#define REP(i,a,b) for(int i=a;i<b;i++)#define REV(i,a,b) for(int i=a-1;i>=b;i--)#define MEM(a,x) memset(a,x,sizeof a)#define ll __int64using namespace std;int n,m;char map[210][210];int vis[210][210];int sx,sy,ex,ey;int dir[4][2]={{0,-1},{1,0},{0,1},{-1,0}};struct node{ int x,y; int step; bool operator <(const node p)const { return step>p.step; }};node p,q;void bfs(){ priority_queue<node> Q; q.x=sx; q.y=sy; q.step=0; vis[q.x][q.y]=1; Q.push(q); bool flag=1; while(!Q.empty()) { q=Q.top(); Q.pop(); if(q.x==ex&&q.y==ey) { printf("%d\n",q.step); return; } for(int i=0;i<4;i++) { p.x=q.x+dir[i][0]; p.y=q.y+dir[i][1]; if(p.x>=0&&p.x<n&&p.y>=0&&p.y<m&&!vis[p.x][p.y]&&map[p.x][p.y]!='#') { p.step=q.step+1; vis[p.x][p.y]=1; if(map[p.x][p.y]=='a') { printf("%d\n",p.step); return; } if(map[p.x][p.y]=='x') p.step++; Q.push(p); } } } if(flag) printf("Poor ANGEL has to stay in the prison all his life.\n");}int main(){//freopen("ceshi.txt","r",stdin); while(scanf("%d%d",&n,&m)!=EOF) { for(int i=0;i<n;i++) { scanf("%s",map[i]); for(int j=0;j<m;j++) { if(map[i][j]=='r') { sx=i; sy=j; } if(map[i][j]=='a') { ex=i; ey=j; } } } MEM(vis,0); bfs(); } return 0;}
0 0
- hnu 1242 Rescue
- 1242 Rescue
- 1242 Rescue
- hdu 1242 Rescue
- 1242 rescue 广搜
- hdoj 1242 Rescue(bfs)
- HDU-1242-Rescue
- HDU 1242 Rescue
- HDU-1242 Rescue
- hdoj 1242 Rescue
- hdoj 1242 Rescue
- hdu 1242 Rescue
- hdu 1242 Rescue<java>
- hdu 1242 rescue
- HDU-1242:Rescue
- HDU 1242 Rescue
- HDU 1242 Rescue
- hdu 1242 Rescue
- Java RMI之HelloWorld篇
- 阿里校招笔试题
- 4.Spring DI(依赖注入)
- NandFlash的读写操作
- UVa 11076 - Add Again (排列之和 组合数学)
- hnu 1242 Rescue
- PYTHON基础(转)
- DSP/BIOS使用之初窥门径——滴答时钟及烧写Flash
- HDU 1171
- Mac下使用Eclipse编译C/C++文件出现 launch failed, binary not found 错误的解决办法
- Android事件处理
- PCB设计资料:看到最后才知道是福利
- 用SQL语句生成某个库下所有存储过程脚本,并每个存为一个文件
- div 模拟select