ahu-595-撒哈拉大冒险
2015-09-24 22:40
218 查看
坑点:输入不能一个个字符输入,跟hd不一样数据坑
思路 循环 x=(x%n+n)%n+搜索队列
交了我的和硕神的代码,200ms和80ms,只是因为我的是用queue库函数,硕神手撸stack,所以说亲手撸的要节省很多时间。
第一道无限循环的题学会很多。
思路 循环 x=(x%n+n)%n+搜索队列
交了我的和硕神的代码,200ms和80ms,只是因为我的是用queue库函数,硕神手撸stack,所以说亲手撸的要节省很多时间。
第一道无限循环的题学会很多。
#include <cstdio> #include <cmath> #include <cstring> #include <cstdlib> #include <stack> #include <queue> #include <set> #include <map> #include <iostream> #include <algorithm> using namespace std; struct node{ int x,y; }; int i,j,k,n,m,t,starx,stary,color[1005][1005],color2[1015][1015][2],bu[4][2] = {1,0,-1,0,0,1,0,-1}; char mp[1015][1015]; int main() { scanf("%d",&t); while(t--) { bool SYM = false; scanf("%d%d",&n,&m); memset(color,0,sizeof(color)); for(i=0; i<n; i++) { scanf("%s",mp[i]); for(j=0; j<m; j++) { if(mp[i][j]=='S'){ starx = i; stary = j; } } } // bfs---------------------------------------------------------------- queue<node>point; node node1,node2; node1.x = starx; node1.y = stary; point.push(node1); color[starx][stary] = 1; color2[starx][stary][0] = starx; color2[starx][stary][1] = stary; while(!point.empty()) { node1 = point.front(); point.pop(); if(SYM == true)break; for(i=0; i<4; i++) { int X = node1.x+bu[i][0],Y = node1.y+bu[i][1]; int XX = (X%n+n)%n,YY = (Y%m+m)%m; if(mp[XX][YY] !='#') { if(color[XX][YY]==0) { node2.x = X; node2.y = Y; color[XX][YY] = 1; point.push(node2); color2[XX][YY][0] = X; color2[XX][YY][1] = Y; } else if(X!=color2[XX][YY][0] || Y!=color2[XX][YY][1])SYM = true; } } } if(SYM == true)printf("YES\n"); else printf("NO\n"); } return 0; }
相关文章推荐
- 断舍离——将晦气和无力清扫出去
- WXY的行为和ZP的行为
- windows sdk ddk wdk
- jquery-easyui实现页面布局和增删改查操作(SSH2框架支持)转载
- C++ 项目经验总结:程序严谨性(一)
- 简易计算器
- 基于模拟落体碰撞的优化算法——本科毕业论文
- scandisk常用方法
- 《深入理解Linux网络技术内幕》阅读笔记(一)
- 动太规划问题
- 关于语音分帧时有重叠部分的原因分析
- windows 无法上网问题解决一例
- android布局
- CentOS6.5下安装apache2.2和PHP 5.5.28
- JavaScript权威设计--Window对象(简要学习笔记十三)
- 当月日历
- 2015-09-24
- 细说Java内部类, 静态内部类, 局部类, 匿名内部类
- mysql教程
- 【 UIImageView图片控件】