HDU 4771Stealing Harry Potter's Precious
来源:互联网 发布:水果淘宝店铺介绍范文 编辑:程序博客网 时间:2024/05/21 06:35
A 点击打开链接
#include<stdio.h>#include<string.h>#include<stack>#include<string>#include<math.h>#include<queue>#include<set>#include<algorithm>#include<iostream>#include<vector>#include<map>using namespace std;#define LL long long#define inf 0x3f3f3f3f#define N 110struct node{ int x,y,z;}net,cur;int mark[1<<4][N][N];char Map[N][N];int d[4][2]={0,1,0,-1,1,0,-1,0};node K[5];int n,m,k;bool judge(int x,int y,int z){ if(x>n||x<1||y>m||y<1) return 0; if(mark[z][x][y]>0||Map[x][y]=='#') return 0; return 1;}int BFS(int sx ,int sy){ queue<node>q; cur.x = sx,cur.y = sy,cur.z = 0; memset(mark,0,sizeof(mark)); q.push(cur); mark[cur.z][cur.x][cur.y] = 1; while(!q.empty()) { cur = q.front();q.pop(); if(cur.z == (1<<k) - 1) return mark[cur.z][cur.x][cur.y] - 1; for(int i=0;i<4;i++) { net.x=cur.x+d[i][0]; net.y=cur.y+d[i][1]; net.z=cur.z; int mk=0; for(int j=1;j<=k;j++) if(net.x==K[j].x&&net.y==K[j].y) { mk=j; break; } if(mk) net.z=cur.z|(1<<(mk-1)); if(judge(net.x,net.y,net.z)) { mark[net.z][net.x][net.y]=mark[cur.z][cur.x][cur.y]+1; q.push(net); } } } return -1;}int main (){ int i,j,sx,sy; while(scanf("%d%d",&n,&m),n+m) { for(i=1;i<=n;i++) { scanf("%s",Map[i]+1); for(j=1;j<=m;j++) { if(Map[i][j]=='@') sx=i,sy=j; } } scanf("%d",&k); for(i=1;i<=k;i++) scanf("%d%d",&K[i].x,&K[i].y); printf("%d\n",BFS(sx,sy)); } return 0;}
0 0
- hdu 4771 - Stealing Harry Potter's Precious
- HDU:4771 Stealing Harry Potter's Precious
- HDU 4771 Stealing Harry Potter's Precious
- hdu 4771 Stealing Harry Potter's Precious
- hdu 4771 Stealing Harry Potter's Precious
- HDU 4771 Stealing Harry Potter's Precious
- hdu 4771 Stealing Harry Potter's Precious
- hdu 4771 Stealing Harry Potter's Precious
- HDU 4771 Stealing Harry Potter's Precious
- hdu 4771 Stealing Harry Potter's Precious
- HDU 4771 Stealing Harry Potter's Precious
- hdu 4771 Stealing Harry Potter's Precious
- HDU 4771 Stealing Harry Potter's Precious
- HDU 4771 Stealing Harry Potter's Precious
- HDU 4771Stealing Harry Potter's Precious
- HDU 4771 Stealing Harry Potter's Precious
- HDU 4771 Stealing Harry Potter's Precious
- HDU 4771 Stealing Harry Potter's Precious
- java--通过DOM方式对xml文件进行读取的简单实例
- iOS开发 - 手势识别
- 多台服务器session、cookie之间的关系
- solaris 10中设置oracle数据库监听80端口
- 武装Eclipse
- HDU 4771Stealing Harry Potter's Precious
- 资源文件(多语言)的管理
- QDU第二次月赛 排在第几个(康拓展开)
- 【笔记&代码】 多核编程实战Multicore Application Programming For Windows
- Matlab绘图-很详细,很全面
- 彻底解决INSTALL_FAILED_UPDATE_INCOMPATIBLE的安装错误
- JS计时器
- sql虚构一个常量字段的查询
- QDU第二次月赛 简单题