hdu 1175
来源:互联网 发布:stc单片机价格 编辑:程序博客网 时间:2024/05/29 02:43
#include<iostream>
#include<queue>
using namespace std;
struct node{
int x,y;
int time;
int d;
};
int map[1010][1010];
int hash[1010][1010];
int dir[4][2] = {{1,0},{-1,0},{0,-1},{0,1}};
int m,n,sx,sy,dx,dy;
void bfs(int x,int y)
{
memset(hash,3,sizeof(hash));
queue<node>q;
node N,P;
int i;
N.x = x;
N.y = y;
N.time = 0;
N.d = 5;
q.push(N);
while(!q.empty())
{
N = q.front();
q.pop();
for(i = 0; i < 4; i++)
{
P.x = N.x + dir[i][0];
P.y = N.y + dir[i][1];
P.d = i;
if(P.x <= n && P.y <= m &&P.x > 0 && P.y > 0 && (map[P.x][P.y] == 0 || P.x == dx && P.y == dy)&& N.time <= 2)
{
if(P.d == N.d || N.d == 5)
{
P.time = N.time ;
}
else
{
P.time = N.time + 1;
}
if( hash[P.x][P.y] >= P.time && P.time <= 2)
{
hash[P.x][P.y] = P.time;
q.push(P);
}
}
}
}
if(hash[dx][dy] <= 2)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
void main()
{
int t,i,j;
while(cin>>n>>m)
{
if(m == 0 && n == 0)
continue;
for(i = 1; i <= n; i++)
for(j = 1; j <= m; j++)
{
cin>>map[i][j];
//hash[i][j] = 3;
}
cin>>t;
for(i = 0; i < t; i++)
{
cin>>sx>>sy>>dx>>dy;
if(map[sx][sy] == map[dx][dy] && map[sx][sy] != 0 && map[dx][dy] != 0 &&!(sx == dx && sy == dy))
{
bfs(sx,sy);
}
else
{
cout<<"NO"<<endl;
continue;
}
}
//bfs(sx,sy);
}
}
- hdu 1175
- HDU 1175
- hdu 1175
- HDU 1175
- hdu 1175
- HDU 1175
- hdu 1175
- hdu 1175
- HDU 1175
- hdu 1175
- HDU 1175
- hdu 1175
- hdu 1175 连连看
- hdu 1175 bfs
- hdu 1175 连连看
- hdu 1175 连连看
- HDU 1175 连连看
- HDU 1175 ( 连连看 )
- 分工、流程、标准、职业化——将你的代码工业化
- 最简便的方式使用多线程
- hdu 3415 堆优化
- [白象集团.net培训课程].Lesson1
- Keep on keeping on
- hdu 1175
- GSM GPRS TC35
- hdu 1052
- 高斯平滑 高斯模糊 高斯滤波器 ( Gaussian Smoothing, Gaussian Blur, Gaussian Filter ) C++ 实现
- 正则表达式语法
- 正则表达式语法
- mysql各版本之间的差别(转)
- 优秀技术地址总结
- C#关于DateTime得到的当前时间的格式问题