poj 3948 迷宫问题 且行且珍惜--
来源:互联网 发布:全国汽车保有量数据 编辑:程序博客网 时间:2024/05/21 14:57
这道题没有什么特别要说的,我估计写的比别人的代码多耗一点时间,而且还多一些内存, 但是我感觉我的理解起来挺容易的就是用队列把每一步走的点存到你开的结构体的数组里面这样你就可以很方便的输出结果了,比较坑的是,这道题的括号建议读者写的时候最好复制下你们题的括号,我因为自己打的括号然后wa了一次,复制了下然后对了‘
AC代码:
#include<stdio.h>#include<string.h>#include<queue>using namespace std;struct node{ int a, b, k; int x[100];///存下经过的点的横坐标 int y[100];///存下经过的点的纵坐标};int to[4][2]={{1,0},{-1,0},{0,1},{0,-1}};///四个方向int main(){ int a[7][7], v[7][7]; int i, j; for(i=0;i<5;i++) for(j=0;j<5;j++) scanf("%d",&a[i][j]); queue<node> q; node w,e; w.a=0;w.b=0;w.k=0; w.x[0]=0;w.y[0]=0; q.push(w); memset(v,0,sizeof(v)); v[0][0]=1; while(!q.empty()) { e=q.front(); q.pop(); if(e.a==4 && e.b==4) { for(i=0;i<=e.k;i++) { printf("(%d, %d)\n",e.x[i],e.y[i]); } break; } for(i=0;i<4;i++) { int X=e.a+to[i][0]; int Y=e.b+to[i][1]; int K=e.k; if(X>=0 && X<5 && Y>=0 && Y<5 &&!v[X][Y] && !a[X][Y]) { w.a=X;w.b=Y;v[X][Y]=1; for(j=0;j<=K;j++)///把上个点的经过的点复制到这个点内 { w.x[j]=e.x[j]; w.y[j]=e.y[j]; } w.k=K+1; w.x[K+1]=X;w.y[K+1]=Y;///把这个点存到数组里面 q.push(w); } } } return 0;}
’
0 0
- poj 3948 迷宫问题 且行且珍惜--
- poj 3126 队列 且行且珍惜---
- 且行且珍惜
- 且行且珍惜
- 且行且珍惜!
- 且行且珍惜
- 且行且珍惜
- 且行且珍惜
- 且行且珍惜
- 且行且珍惜
- 且行且珍惜
- 2008,且行且珍惜
- 且行且珍惜吧!!!
- poj 3278 队列的经典题目 且行且珍惜----
- 生活不简单,且行且珍惜
- 婚姻不易,且行且珍惜
- 英语学习--且行且珍惜
- 人间四月天,且行且珍惜
- Mongodb集群小结
- php使用curl远程下载微信的图片到自己的服务器
- python项目打包成可执行的exe文件
- HACM2039 三角形
- Python学习笔记:list,tuple和str
- poj 3948 迷宫问题 且行且珍惜--
- 读书笔记
- How to justify if a windows program is 32 bit or 64 bit
- CodeForces 703D Mishka and Interesting sum
- 操作系统进程与线程
- 利用搜索法求百万以内的素数
- WIN7(64bit)编译运行gh0st3.6
- Quartz使用技巧总结
- Android ExpandableListView使用指南