讲实话,做得很糟糕,不过这是我广搜的处女题,而且调试了两天才Accept,前面基本上什么错误都出现了,特别是MLE,不会剪枝,做得很吃力,为自己喝彩!
更搞笑的是10000MS的题目,我刚好用了9890MS
Problem : 1175 ( 连连看 ) Judge Status : Accepted
RunId : 5590624 Language : G++ Author : ssun
Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta
#include<iostream>
#include<string>
#include<queue>
using namespace std;
const int N = 1005;
int m,n,q;
int map[N][N];
int visit[N][N];
int x1,y1,x2,y2;
int direct[4][2] = {0,-1,1,0,-1,0,0,1};
struct point{
int x;
int y;
int dir;
int round;
};
bool bfs(int x,int y,int dir, int round)
{
int i;
queue<point> pp;
point now = {x,y,dir,round};
pp.push(now);
while(!pp.empty())
{
point temp = pp.front();
pp.pop();
if(temp.round > 2) continue;
for(i=0; i<4; i++)
{
now.x = temp.x + direct[i][0];
now.y = temp.y + direct[i][1];
if(temp.dir==i || temp.dir == 4 ) now.round = temp.round;
else now.round = temp.round + 1;
now.dir = i;
if(now.x == x2 && now.y == y2 && now.round<=2) return true;
if(!map[now.x][now.y] && !visit[now.x][now.y] && now.x >0 && now.y >0 && now.x < n+1 && now.y < m+1)
{
pp.push(now);
}
}
visit[temp.x][temp.y] = 1;
}
return false;
}
int main()
{
int i,j;
while(cin>>n>>m && (m!=0||n!=0))
{
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
cin>>map[i][j];
}
}
cin>>q;
while(q--)
{
memset(visit,0,sizeof(visit));
cin>>x1>>y1>>x2>>y2;
if(map[x1][y1] != map[x2][y2])
{
cout<<"NO"<<endl;
continue;
}
if(map[x1][y1]!=0 && bfs(x1,y1,4,0))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
return 0;
}
/*
5 5
1 2 3 4 5
0 0 0 0 0
0 0 0 0 0
0 0 0 2 2
5 4 1 2 1
3
1 5 5 1
1 1 5 5
1 2 5 4
4 4
1 2 3 4
0 0 0 0
0 0 0 0
3 2 1 4
3
1 1 4 3
1 3 3 1
*/
分享到:
相关推荐
算法-连连看(HDU-1175)(包含源程序).rar
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
HDU1059的代码
杭电ACMhdu1163
hdu1001解题报告
hdu 1574 passed sorce
语言:中文 (简体) 身在杭电必用的Chrome插件! HDU-GO是一款适用于杭州电子科技大学选课系统的Chrome拓展程序,具有自动抢课、自动学评教、自动计算学分功能。
HDU的一题........HDU DP动态规
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
hdu2101AC代码
搜索 dfs 解题代码 hdu1241
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
ACM HDU题目分类,我自己总结的大概只有十来个吧
HDU最全ac代码
hdu 1166线段树代码
hdu动态规划算法集锦
hdu题目分类
自己做的HDU ACM已经AC的题目
hdu-acm源代码(上百题)hdu-acm源代码、hdu-acm源代码hdu-acm源代码