HDOJ 1175 连连看 (bfs)
来源:互联网 发布:计量经济学论文数据 编辑:程序博客网 时间:2024/06/06 08:39
题目链接:~( ̄▽ ̄~)(~ ̄▽ ̄)~
思路:用bfs一次把这个方向上能到的点入队
code:
#include <stdio.h>int m = 0, n = 0, front = 0, rear = 0, map[1002][1002], used[1002][1002];int X1 = 0, Y1 = 0, X2 = 0, Y2 = 0;int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};typedef struct{ int x, y, count;}node;node step, quene[1000*1000+1];int bfs(){ int i = 0, x = 0, y = 0, fx = 0, fy = 0, count = 0; quene[rear++] = step; while(front<rear) { x = quene[front].x; y = quene[front].y; count = quene[front++].count; for(i = 0; i<4; i++) { fx = x+dir[i][0]; fy = y+dir[i][1]; while(!map[fx][fy] && count<3 && fx>0 && fx<=n && fy>0 &&fy<=m && !used[fx][fy])//这方向上能到的点入队 { used[fx][fy] = 1; step.x = fx; step.y = fy; step.count = count+1; quene[rear++] = step; fx += dir[i][0]; fy += dir[i][1]; } if(fx == X2 && fy == Y2 && count<3) return 1; } } return 0;}int main(){ int i = 0, j= 0, q = 0; while(scanf("%d %d",&n, &m) , n && m) { for(i = 1; i<=n; i++) for(j = 1; j<=m; j++) scanf("%d",&map[i][j]); scanf("%d",&q); while(q--) { for(i = 1; i<=n; i++) for(j = 1; j<=m; j++) used[i][j] = 0; scanf("%d %d %d %d",&X1, &Y1, &X2, &Y2); if((map[X1][Y1] != map[X2][Y2] || !map[X1][Y1] || !map[X2][Y2]) || (X1==X2 && Y2 == Y1)) printf("NO\n"); else { front = rear = 0; step.x = X1; step.y = Y1;step.count = 0; if(bfs()) printf("YES\n"); else printf("NO\n"); } } } return 0;}
- HDOJ 1175 连连看 (bfs)
- hdoj 1175 连连看【bfs】
- hdoj 1175 连连看(BFS)
- HDOJ 1175 连连看 DFS BFS
- HDOJ 1175 连连看(BFS)
- hdoj 连连看 1175 (bfs)
- hdoj 1175-连连看
- HDOJ 1175 连连看
- HDOJ 1175 连连看
- hdoj-【1175 连连看】
- hdu 1175 连连看 bfs
- hdu 1175 连连看 (BFS)
- hdu 1175 连连看 BFS
- Hdu 1175 连连看 [Bfs]
- HDU 1175 连连看(BFS)
- HDU 1175 连连看【BFS】
- HDU 1175 连连看(BFS)
- HDU 1175 连连看 BFS
- 让博客快速提升网站排名的关键设置
- linux 打包、压缩、解压小结:
- ASP.NET 用MultiView和View实现选项卡效果
- Google Map API使用中出现的“google未定义”解决办法
- linux free命令解析
- HDOJ 1175 连连看 (bfs)
- shell中continue和break区别
- C#中对数据库文件的导入导出Excel
- shell test用shell test用法
- JS操作cookie工具函数01
- linux nslookup
- Oracle 分析函数——函数RANK,DENSE_RANK,FIRST,LAST…
- 关于VMware ESX Server客户端连接不上等问题的解决
- java学习笔记