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 ...
随机推荐
- Mac和iOS开发资源汇总—更新于2013-10-14
小引本文主要汇集一些苹果开发的资源,会经常更新,建议大家把这篇文章单独收藏(在浏览器中按command+D).今天(2013年10月14日)收录了answer哥(黄爱武)的博客,欢迎大家围观! 今天( ...
- Dotfuscator Professional Edition获取代码发布和混淆代码
1 Dotfuscator Professional Edition 4.9 破解版 下载地址:http://www.pc0359.cn/downinfo/39815.html 备份地址:C:\D\9 ...
- 在命令提示符下启动并使用JVM时,简单设置堆
公司电脑内存太小了,只有8G:或者说JVM默认启动占用内存太大了,同时启动多个服务内存就炸了. 比如: java -Xmx128m -Xms64m -Xmn32m -Xss16m -jar eurek ...
- 迭代删除元素 并发bug 低级错误
方法一:HashMap<String, Integer> myHashMap = new HashMap<>();myHashMap.put("1", 1) ...
- git cherry-pick用法
场景: 如果你的应用已经发布了一个版本2.0, 代码分支叫release-2.0, 现在正在开发3.0, 代码的分支叫dev-3.0. 那么有一天产品说, 要把正在开发的某个特性提前上线, 也就是说要 ...
- linux一些基本常识(四)
tail -f时时监控 一开启内存最小位u原则,尽量优化代码 grep -v "" /etc/passwd 这样行不行 怎么清除last nice调整进程运行级别 pkill是匹配 ...
- Spring编程式事务管理
--------------------siwuxie095 Spring 编程式事务管理 以转账为例 ...
- 找不到reportviewer控件在哪儿
請自行加入ReportViewer(9.0)到工具箱之中. 如下圖,
- [leetcode]113. Path Sum II路径和(返回路径)
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- ImageView小技巧
ImageView截取图片的方式 centerCrop:以中心点为基准 将图片的最短边与ImageView宽度匹配 其他部分裁掉centerInside: 以中心点为基准 将图片最长边 缩进控件去