hdu - Problem 1175 连连看 【bfs】

限时加码!20+主流AI编程工具免费用 购周边加赠Coding Plan Lite,Claude Code、Cursor等即刻畅享,学习进阶更高效! 阅读详情

http://acm.hdu.edu.cn/showproblem.php?pid=1175

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32089    Accepted Submission(s): 7900


Problem Description
“连连看”相信很多人都玩过。没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子。如果某两个相同的棋子,可以通过一条线连起来(这条线不能经过其它棋子),而且线的转折次数不超过两次,那么这两个棋子就可以在棋盘上消去。不好意思,由于我以前没有玩过连连看,咨询了同学的意见,连线不能从外面绕过去的,但事实上这是错的。现在已经酿成大祸,就只能将错就错了,连线不能从外围绕过。
玩家鼠标先后点击两块棋子,试图将他们消去,然后游戏的后台判断这两个方格能不能消去。现在你的任务就是写这个后台程序。
 

Input
输入数据有多组。每组数据的第一行有两个正整数n,m(0<n<=1000,0<m<1000),分别表示棋盘的行数与列数。在接下来的n行中,每行有m个非负整数描述棋盘的方格分布。0表示这个位置没有棋子,正整数表示棋子的类型。接下来的一行是一个正整数q(0<q<50),表示下面有q次询问。在接下来的q行里,每行有四个正整数x1,y1,x2,y2,表示询问第x1行y1列的棋子与第x2行y2列的棋子能不能消去。n=0,m=0时,输入结束。
注意:询问之间无先后关系,都是针对当前状态的!
 

Output
每一组输入数据对应一行输出。如果能消去则输出"YES",不能则输出"NO"。
 

Sample Input
  
3 4 1 2 3 4 0 0 0 0 4 3 2 1 4 1 1 3 4 1 1 2 4 1 1 3 3 2 1 2 4 3 4 0 1 4 3 0 2 4 1 0 0 0 0 2 1 1 2 4 1 3 2 3 0 0
 

Sample Output
  
YES NO NO NO NO YES
 

Author
lwg
 

Recommend
We have carefully selected several similar problems for you:   1180  1072  1016  1026  1240 
 

好久没有做图的题了 ,水下,这个就是有个拐点限制。

#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <stack>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
//#include <bits/stdc++.h>
//#define LOACL
#define space " "
using namespace std;
typedef long long LL;
typedef __int64 Int;
typedef pair<int, int> paii;
const int INF = 0x3f3f3f3f;
const double ESP = 1e-5;
const double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const int MAXN = 1000 + 10;
int data[MAXN][MAXN], n, m;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
struct node {
	int x, y;
	int dit;
	int turn;
} loc[2], t, temp;
bool bfs(node s, node e) {
	queue <node> que;
	bool vis[MAXN][MAXN];
	memset(vis, false, sizeof(vis));
	for (int i = 0; i < 4; i++) {
		t = s;
		t.x = s.x + dx[i];
		t.y = s.y + dy[i];
		t.dit = i;t.turn = 2;
		que.push(t);
	}
	while (que.size()) {
		temp = que.front(); que.pop();
		//cout << temp.x << space << temp.y << space << temp.turn << endl;//cout << "afh" << endl;
		vis[temp.x][temp.y] = true;
		if (temp.x < 1 || temp.y < 1 || temp.x > n || temp.y > m) continue;
		if (temp.x == e.x && temp.y == e.y) return true;
		if (data[temp.x][temp.y]) continue;
		if (temp.turn) {
			for (int i = 0; i < 4; i++) {
				if (i == temp.dit) continue;
				t.x = temp.x + dx[i];
				t.y = temp.y + dy[i];
				t.dit = i;
				t.turn = temp.turn - 1;
				if (!vis[t.x][t.y]) que.push(t);
			}
		}
		t.x = temp.x + dx[temp.dit];
		t.y = temp.y + dy[temp.dit];
		t.dit = temp.dit;
		t.turn = temp.turn;
		if (!vis[t.x][t.y]) que.push(t);
	}
	return false;
}
int main() {
	while (scanf("%d%d", &n, &m) != EOF) {
		if (n == 0 && m == 0) break;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				scanf("%d", &data[i][j]);
			}
		}
		int op;
		scanf("%d", &op);
		while (op--) {
			scanf("%d%d%d%d", &loc[0].x, &loc[0].y, &loc[1].x, &loc[1].y);
			if (data[loc[0].x][loc[0].y] != data[loc[1].x][loc[1].y]) printf("NO\n");
			else if (!data[loc[0].x][loc[0].y] || !data[loc[1].x][loc[1].y]) printf("NO\n");
			else if (loc[0].x == loc[1].x && loc[0].y == loc[1].y) printf("YES\n");
			else {
				if (bfs(loc[0], loc[1])) printf("YES\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
}
/*
2 2
1 0
0 1
1
1 1
2 2
*/


武汉理工大学数据结构综合实验——连连看游戏综合实践 文章目录实验目的主要仪器设备及耗材一、实验要求二、分析与设计(非线性结构)1.数据结构的设计2.核心算法设计一条直线消子两条直线消子三条直线消子初始化游戏地图搜寻路径提示和重排3.测试用例设计4.测试效果总结 实验目的 (1)线性结构实验目的 调研连连看游戏,了解连连看游戏的功能和规则等 掌握集成开发工具VS2019的使用和C++的基础编程 了解MFC框架 了解线性结构,掌握数组的遍历、消子和胜负判断等算法 了解企业软件开发过程,应用迭代开发思路进行项目开发,养成良好的编程习惯和培养软件工程化思维 . 阅读详情

相关推荐

【教学类-12-08】20221111《连连看竖版6*6 (3套题目空心图案(中班教学)》(中班主题《》)

【教学类-12-08】20221111《连连看竖版6*6 (3套题目空心图案(中班教学)》(中班主题《》)

reasonsummer的博客 1035

武汉理工大学数据结构与算法实验——欢乐连连看(非线性结构)

注意:这是武汉理工大学数据结构与算法实验欢乐连连看的非线性结构!!!!!!注意这是非线性的,实验完成了除闯关模式和排行榜以外的所有功能,已经验收通过

武汉理工大学实验:连连看

直接运行需要调试,资源文件在LianLianKan\LLK\theme\picture 中,自行更改

HDU 1175(搜索题,BFS

连连看<br />Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)<br />Total Submission(s): 2678    Accepted Submission(s): 608<br /><br />Problem Description“连连看”相信很多人都玩过。没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子。如果某两个相同的棋子,可以通过一条

-- bird -- 1154

bfs连连看hdu1175),HDU 1253 胜利大逃亡(三维数组+bfs),HDU 1495 非常可乐(BFS+模拟)

连连看hdu1175) “连连看”相信很多人都玩过。没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子。如果某两个相同的棋子,可以通过一条线连起来(这条线不能经过其它棋子),而且线的转折次数不超过两次,那么这两个棋子就可以在棋盘上消去。不好意思,由于我以前没有玩过连连看,咨询了同学的意见,连线不能从外面绕过去的,但事实上这是错的。现在已经酿成大祸,就只能将错就错了,连线不能从外围绕过。 玩家鼠标先后点击两块棋子,试图将他们消去,然后游戏的后台判断这两个方格能不能消去。现在你的任务就

wangjunjie_123的博客 222

HDU 1175 连连看(BFS或DFS)

连连看               Time Limit: 20000/10000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)                      Total Submission(s): 12814Accepted Submission(s): 3351 Prob...

MengDeMao1234的博客 261

连连看(hdu1175 bfs+方向记录+贪心剪枝)

连连看 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13007    Accepted Submission(s): 3404 Problem Description “连连看”相信很多人都玩过。没玩过也没

leonharetd的专栏 996

HDU 1175 连连看

连连看 Time Limit : 20000/10000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 173   Accepted Submission(s) : 41 Font: Times New Roman | Verdana | Georgia Fon

Puya的博客 354

HDU1175 连连看

广搜 判断两点能否相连且路径至多有两个转折。 思路:使用二维数组记录到达某点的最小转弯次数(不是最小步数) #include #include #include #include #include #include #include #include #include #pragma comment(linker, "/STACK:1024000000,1024000000

Ice_SCReam的博客 313

hdu 1175 连连看

点击打开链接 与1728类似,但写出来后一直超时。。。 最后把数组改为1001(原来为1024),就AC了。。 #include"stdio.h" #include"string.h" #include"queue" using namespace std; int dir[4][2]={1,0,0,1,-1,0,0,-1}; int map[1001][1001]; int v

hello_fei 533

BFS小结(持续更新中)

转载请注明出处,谢谢 http://blog.csdn.net/ACM_cxlove?viewmode=contents           by---cxlove 刚好yobobobo最近做BFS,我也被渲染了,当是复习一下,也总结一下吧,大部分是HDOJ上的BFS题目,由于本人时间有限,会持续更新 HDU 1548 http://acm.hdu.edu.cn/showprobl

窝不是爱酱,喵~~~~ 7025

HDU Problem 2612 Find a way 【BFS

Find a way Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10324    Accepted Submission(s): 3365 Problem Description Pass a year le

博客已搬迁到http://www.cnblogs.com/cniwoq/ 321

HDU 1254 推箱子(双BFS

推箱子 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8329    Accepted Submission(s): 2409 Problem Description 推箱子是一个很经典的游戏.今天我们来玩一个

阿金的ACM 680

杭电oj题目分类

  模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 112...

qq1169091731的博客 382
上一篇: codeforces 233c Cycles【贪心】
下一篇: HDU - problem 1387 Team Queue【队列】
路兔兔123
博客等级 码龄11年 17粉丝 263原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值