zoj 1438 Asteroids! BFS
来源:互联网 发布:网络红猫小斑 编辑:程序博客网 时间:2024/06/05 22:50
BFS题目,现在又做了,还是感觉这种题好玩,呵呵!刚开始没看清题目
The first coordinate in a set indicates the column. Left column = 0.
The second coordinate in a set indicates the row. Top row = 0.,弄反了,莫名其妙的WA了。。。现在就把两个坐标换了一下位置,a了,呵呵!
#include<stdio.h> #include<string.h> typedef struct { int s1[10000]; int s2[10000]; int s3[10000]; }queue; queue que; int head,rear; int map[13][13][13],count[30][30][30],vis[30][30][30]; void In(int x,int y,int z) { que.s1[rear]=x; que.s2[rear]=y; que.s3[rear]=z; rear++; } void Out(int *x,int *y,int *z) { *x=que.s1[head]; *y=que.s2[head]; *z=que.s3[head]; head++; } int isEmpty() { if(head==rear) return 1; else return 0; } int main(){ int i,j,k,n,v1,v2,v3,x1,y1,z1,x2,y2,z2,p1,p2,p3,m,flag; int t1[6]={0,0,0,0,1,-1}; int t2[6]={1,-1,0,0,0,0}; int t3[6]={0,0,1,-1,0,0}; char a[10]; while(scanf("%s%d",a,&n)!=EOF) { getchar(); head=rear=0; memset(vis,0,sizeof(vis)); memset(map,0,sizeof(map)); memset(count,0,sizeof(count)); for(k=0;k<n;k++) for(i=0;i<n;i++) { gets(a); for(j=0;j<n;j++) if(a[j]=='O') map[i][j][k]=1; } scanf("%d%d%d",&y1,&x1,&z1);//这里要注意哦 scanf("%d%d%d",&y2,&x2,&z2); scanf("%s",a); In(x1,y1,z1); vis[x1][y1][z1]=1; flag=1; if(x1==x2&&y1==y2&&z1==z2) { printf("%d 0\n",n); flag=0; } while(!isEmpty()&&flag) { Out(&p1,&p2,&p3); for(m=0;m<6;m++) { i=p1+t1[m];j=p2+t2[m];k=p3+t3[m]; if(i>=0&&i<n&&j>=0&&j<n&&k>=0&&k<n&&!vis[i][j][k]&&map[i][j][k]) { count[i][j][k]=count[p1][p2][p3]+1; vis[i][j][k]=1; if(i==x2&&j==y2&&k==z2) { printf("%d %d\n",n,count[i][j][k]); flag=0; break; } else In(i,j,k); } } } if(flag) printf("NO ROUTE\n"); } return 0;}
- zoj 1438 Asteroids! BFS
- ZOJ 1438 Asteroids!--BFS(注意细节)
- ZOJ 1438-Asteroids!(bfs入门题)
- ZOJ 1438 Asteroids!
- zoj 1438 - Asteroids! 题解
- zoj 1438 Asteroids!
- zoj 1438 || poj 2225 Asteroids!
- POJ2225:Asteroids!(BFS)
- hdu 1240 Asteroids BFS
- HDU1240:Asteroids!(BFS)
- hdu1240 Asteroids! (BFS)
- hdu 1240 Asteroids!bfs
- HDU 1240 Asteroids!(BFS)
- hdu 1240 Asteroids!(BFS)
- Asteroids!(三维BFS)
- HDU 1240 Asteroids! 【BFS】
- hdoj Asteroids! (BFS)
- Asteroids!-裸的BFS
- 读书笔记_windows内核编程基础_part 1
- linux中tar的升级方法
- 编译内核模块 .ko文件的注意事项 缺少:mmzone.h bounds.h
- 惨痛的教训,编译程序时一定要注意c运行时库的选择
- The Show
- zoj 1438 Asteroids! BFS
- 年前的开源项目
- 使用AS3实现旋线运动的动画
- JOJ 2474:Tile My Corridor 平铺棋盘 状态压缩解法
- 活着是为了快乐的生活
- Android 怎么启动一个工作线程及线程如何与UI线程交互
- POJ 2886 Who Gets the Most Candies?(单点更新)
- 数据挖掘对聚类分析的要求
- 发现微软有四种数据库