HDU1175 连连看(bfs) 2016-07-24 13:27 115人阅读 评论(0) 收藏
连连看
Problem Description
玩家鼠标先后点击两块棋子,试图将他们消去,然后游戏的后台判断这两个方格能不能消去。现在你的任务就是写这个后台程序。
Input
注意:询问之间无先后关系,都是针对当前状态的!
Output
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
——————————————————————————————————
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
int map[1005][1005];
int mm[1005][1005];
int m, n, t;
int dir[4][2] = { { -1, 0 }, { 0, -1 }, { 0, 1, }, { 1, 0 } }; struct node
{
int x, y, cnt, dr;
};
bool cheak(int i, int j)
{
if (i <= 0 || i > m || j <= 0 || j > n || map[i][j] != 0)
return 0;
else
return 1;
}
int bfs(int si, int sj, int di, int dj)
{
queue<node>q;
node f, p;
f.x = si;
f.y = sj;
f.cnt = -1;
f.dr = -1;
q.push(f);
while (!q.empty())
{
f = q.front();
q.pop(); for (int i = 0; i < 4; i++)
{
if (f.dr == 3 - i)
{
continue;
}
p.x = f.x + dir[i][0];
p.y = f.y + dir[i][1];
if (f.dr != i)
{
p.cnt = f.cnt + 1;
}
else
p.cnt = f.cnt;
if (p.x == di&&p.y == dj&&p.cnt <= 2)
{
return 1;
}
if (cheak(p.x, p.y)&&(mm[p.x][p.y]==-1||mm[p.x][p.y]>p.cnt))
{
p.dr = i;
q.push(p);
mm[p.x][p.y] = p.cnt;
}
}
}
return 0; }
int main()
{
int T, si, sj, di, dj;
while (~scanf("%d%d", &m, &n)&&(m||n))
{
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
scanf("%d", &map[i][j]);
scanf("%d", &T);
while (T--)
{
memset(mm, -1, sizeof(mm));
scanf("%d%d%d%d", &si, &sj, &di, &dj);
if (map[si][sj] != map[di][dj] || (map[si][sj] == 0 && map[di][dj] == 0)||(si==di&&sj==dj))
{
printf("NO\n");
continue;
}
int ans = bfs(si, sj, di, dj);
if (ans)
printf("YES\n");
else
printf("NO\n");
}
}
return 0; }
HDU1175 连连看(bfs) 2016-07-24 13:27 115人阅读 评论(0) 收藏的更多相关文章
- C# WinForm 透明控件 PictureBox透明 分类: WinForm 2014-07-30 13:27 591人阅读 评论(0) 收藏
1.要实现C# WinForm中的控件与背景的透明,可以通过设置控件的BackColor属性为Transparent,同时设置其父控件.因为在C#中,控件的透明指对父窗体透明.如果不设置Parent属 ...
- HDU1253 胜利大逃亡(BFS) 2016-07-24 13:41 67人阅读 评论(0) 收藏
胜利大逃亡 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示 ...
- APP被苹果APPStore拒绝的各种原因 分类: ios相关 app相关 2015-06-25 17:27 200人阅读 评论(0) 收藏
APP被苹果APPStore拒绝的各种原因 1.程序有重大bug,程序不能启动,或者中途退出. 2.绕过苹果的付费渠道,我们之前游戏里的用兑换码兑换金币. 3.游戏里有实物奖励的话,一定要说清楚,奖励 ...
- POJ1087 A Plug for UNIX 2017-02-12 13:38 40人阅读 评论(0) 收藏
A Plug for UNIX Description You are in charge of setting up the press room for the inaugural meeting ...
- 百度地图-省市县联动加载地图 分类: Demo JavaScript 2015-04-26 13:08 530人阅读 评论(0) 收藏
在平常项目中,我们会遇到这样的业务场景: 客户希望把自己的门店绘制在百度地图上,通过省.市.区的选择,然后加载不同区域下的店铺位置. 先看看效果图吧: 实现思路: 第一步:整理行政区域表: 要实现通过 ...
- Power Network 分类: POJ 2015-07-29 13:55 3人阅读 评论(0) 收藏
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24867 Accepted: 12958 Descr ...
- Oracle错误IMP-00010: 不是有效的导出文件, 头部验证失败 分类: Oracle 2015-07-09 13:56 20人阅读 评论(0) 收藏
Oracle 11g的dmp备份文件导入到Oracle 10g,出现错误信息: Import: Release 10.2.0.1.0 - Production on 星期四 7月 9 13:47:04 ...
- Codeforces807 C. Success Rate 2017-05-08 23:27 91人阅读 评论(0) 收藏
C. Success Rate time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Hdu1969 Pie 2017-01-17 13:12 33人阅读 评论(0) 收藏
Pie Time Limit : 5000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissio ...
随机推荐
- HTML CSS + DIV实现整体布局 part2
9.盒模型的层次关系 我们通过一个经典的盒模型3D立体结构图来理解,如图: 从上往下看,层次关系如下: 第1层:盒子的边框(border), 第2层:元素的内容(content).内边 ...
- etcd ui
https://github.com/henszey/etcd-browser docker build --build-arg http_proxy=http://109.105.4.17:3128 ...
- 大型运输行业实战_day07_1_订单查看实现
1.业务分析 每个在窗口售票的售票员都应该可以随时查看自己的售票信息 简单的界面入口如图所示: 对应的html代码: <button onclick="orderDetail()&qu ...
- jQuery源码解读一
(function(window,undefined){...})(window); 这是一个典型的自执行的匿名函数. 为什么会有一个名为undefined的形参呢? undefined不是常量,可以 ...
- cloudrea manager 调整datanode数据存储目录
由于datanode所需磁盘空间较大,所以工作中可能会涉及到给datanode增加磁盘目录或者更改数据目录 CM停止该datanode节点 CM页面增加目录或者修改目录 如果是修改目录的话 需要将服务 ...
- ASP.NET中的URL编码解码(转)
在对URL进行编码时,该用哪一个?这两都使用上有什么区别吗?测试: string file="文件上(传)篇.doc";string Server_UrlEncode=Server ...
- jq闭包
var jy = jQuery.noConflict(); (function($){ //里面跟jq的所有代码 })(jy)
- cdoj844-程序设计竞赛 (线段树的区间最大连续和)【线段树】
http://acm.uestc.edu.cn/#/problem/show/844 程序设计竞赛 Time Limit: 3000/1000MS (Java/Others) Memory L ...
- 分割回文串 · Palindrome Partitioning
[抄题]: 给定一个字符串s,将s分割成一些子串,使每个子串都是回文串. 返回s所有可能的回文串分割方案. 给出 s = "aab",返回 [ ["aa", & ...
- Spring框架的IOC之注解方式的快速入门
1. 步骤一:导入注解开发所有需要的jar包 * 引入IOC容器必须的6个jar包 * 多引入一个:Spring框架的AOP的jar包,spring-aop的jar包 2. 步骤二:创建对应的包结构, ...