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 ...
随机推荐
- 在SQL Server中使用CLR调用.NET方法
介绍 我们一起来做个示例,在.NET中新建一个类,并在这个类里新建一个方法,然后在SQL Server中调用这个方法.按照微软所述,通过宿主 Microsoft .NET Framework 2 ...
- 在Windows下远程连接CentOS6
远程连接linux服务器的方式:以显示的类型来分类,可以分为字符界面和图形界面两种.字符界面软件有SecureCRT.PUTTY等:图形界面有Xmanager.Xdmcp和VNC软件等.
- 第六章 图(d)深度优先搜索
- UVa 1595 Symmetry(set)
We call a figure made of points is left-right symmetric as it is possible to fold the sheet of paper ...
- [leetcode]523. Continuous Subarray Sum连续子数组和(为K的倍数)
Given a list of non-negative numbers and a target integer k, write a function to check if the array ...
- sublime text3 配置
1.在sublime text官网下载安装文件并安装 http://www.sublimetext.com/ 2.安装sublime的package control 参考网址:https://pack ...
- Golang之时间、日期类型
孤身只影的一直小地鼠,艰难的走在路上 package main import ( "fmt" "time" ) //获取时间的格式 func testTime( ...
- Strand Specific mRNA sequencing 之重要性与分析
Strand Specific mRNA sequencing 之重要性与分析 发表评论 2,761 A+ 所属分类:Bioinformatics 收 藏 研究生物基因转录体的方法有许多种,而使 ...
- HTML5新特性:范围样式
原文出处:http://blog.csdn.net/hfahe/article/details/7381141 Chromium 最近实现了一个HTML5的新特性:范围样式,又叫做< ...
- pca总结,非常详细
#coding=utf- from numpy import * '''通过方差的百分比来计算将数据降到多少维是比较合适的, 函数传入的参数是特征值和百分比percentage,返回需要降到的维度数n ...