hdu1240 poj 2225 三维BFS
来源:互联网 发布:淘宝支付宝账户 编辑:程序博客网 时间:2024/05/18 02:52
http://acm.hdu.edu.cn/showproblem.php?pid=1240
#include <iostream>#include<cstring>#include<cstdio>#include<queue>using namespace std;char map[15][15][15];typedef struct{ int x,y,z; int cont;}node;int main(){ char s[10]; int n,i,j,sx,sy,sz,ex,ey,ez; while(scanf("%s%d",s,&n)!=EOF) { queue<node>q; for(i=0;i<n;i++) { for(j=0;j<n;j++) scanf("%s",map[i][j]); } scanf("%d%d%d",&sx,&sy,&sz); scanf("%d%d%d",&ex,&ey,&ez); scanf("%s",s); if(sx==ex&&sy==ey&&sz==ez) { cout<<n<<" "<<"0"<<endl; continue; } node tem; tem.x=sx; tem.y=sy; tem.z=sz; tem.cont=0; q.push(tem); map[sz][sx][sy]='X'; bool flag=0; while(!q.empty()) { node f=q.front(); q.pop(); int dx[6]={0,1,0,-1,0,0};//row int dy[6]={1,0,-1,0,0,0};//column int dz[6]={0,0,0,0,1,-1};//slice for(i=0;i<6;i++) { int tx=f.x+dx[i]; int ty=f.y+dy[i]; int tz=f.z+dz[i]; tem.x=tx; tem.y=ty; tem.z=tz; tem.cont=f.cont+1; if(tx>=0&&tx<n&&ty>=0&&ty<n&&tz>=0&&tz<n) { if(tx==ex&&ty==ey&&tz==ez) { cout<<n<<" "<<tem.cont<<endl; flag=1; break; } if(map[tz][tx][ty]=='O') { q.push(tem);//cout<<tz<<tx<<ty<<endl; map[tz][tx][ty]='X'; } } } if(flag) break; } if(!flag) cout<<"NO ROUTE"<<endl; } return 0;}
开始写的while(scanf("%s%d",s,&n)&&n)过不了额
http://poj.org/problem?id=2225
输入的时候 x, y换下就行,hdu的输入是不是有问题
#include <iostream>#include<cstring>#include<cstdio>#include<queue>using namespace std;char map[15][15][15];typedef struct{ int x,y,z; int cont;}node;int main(){ char s[10]; int n,i,j,sx,sy,sz,ex,ey,ez; while(scanf("%s%d",s,&n)!=EOF) { queue<node>q; for(i=0;i<n;i++) { for(j=0;j<n;j++) scanf("%s",map[i][j]); } scanf("%d%d%d",&sy,&sx,&sz); scanf("%d%d%d",&ey,&ex,&ez); scanf("%s",s); if(sx==ex&&sy==ey&&sz==ez) { cout<<n<<" "<<"0"<<endl; continue; } node tem; tem.x=sx; tem.y=sy; tem.z=sz; tem.cont=0; q.push(tem); map[sz][sx][sy]='X'; bool flag=0; while(!q.empty()) { node f=q.front(); q.pop(); int dx[6]={0,1,0,-1,0,0};//row int dy[6]={1,0,-1,0,0,0};//column int dz[6]={0,0,0,0,1,-1};//slice for(i=0;i<6;i++) { int tx=f.x+dx[i]; int ty=f.y+dy[i]; int tz=f.z+dz[i]; tem.x=tx; tem.y=ty; tem.z=tz; tem.cont=f.cont+1; if(tx>=0&&tx<n&&ty>=0&&ty<n&&tz>=0&&tz<n) { if(tx==ex&&ty==ey&&tz==ez) { cout<<n<<" "<<tem.cont<<endl; flag=1; break; } if(map[tz][tx][ty]=='O') { q.push(tem);//cout<<tz<<tx<<ty<<endl; map[tz][tx][ty]='X'; } } } if(flag) break; } if(!flag) cout<<"NO ROUTE"<<endl; } return 0;}
- hdu1240 poj 2225 三维BFS
- hdu1240 三维之Bfs
- Hdu1240 Asteroids!(三维BFS)
- hdu1240 Asteroids!(三维bfs水)
- hdu1240三维bfs最短路轻松1A
- ACM-三维BFS之Asteroids!——hdu1240
- HDU1240 Asteroids!-题目意思详解( 三维BFS)
- hdu1240 (bfs)
- poj 2251 三维BFS
- 三维BFS POJ
- POJ-2251三维bfs
- HDU1240:Asteroids!(BFS)
- hdu1240 Asteroids! (BFS)
- HDU1240 Asteroids!(BFS)
- hdu1240 Asteroids!--DFS & BFS
- HDU1240 Asteroids!(BFS)
- BFS---HDU1240 Asteroids!
- HDU1240(BFS)Asteroids!
- 矩阵求导
- flex4/air 护眼健康卫士(源码/air安装包)
- 写给自己
- OpenCV 随机森林 参数
- 在Ubuntu13.04下安装wxErlang
- hdu1240 poj 2225 三维BFS
- 求链表的倒数第K个节点,如果K大于链表长度则返回NULL
- 不可思议
- 第4章 WCDMA
- 2013年4月30日 21:27:48
- 阶段性总结
- 【网络流第四弹】最大点权独立集 ——HDU 1565 方格取数(1)
- 网众linux里启用SSH的方法
- 手把手教你编译RS GIS开源库(一)编译ECW3.3库