8659 Mine Sweeping
时间限制:500MS 内存限制:65535K
提交次数:37 通过次数:15
题型: 编程题 语言: G++;GCC
Description
The opening ceremony of the 28th Asia Game is coming. In order to prevent the game from being attacked by terrorists, Asia Compete Machinery (ACM) takes lots operations as security measures.
Mine sweeping is one of the most important operations, so a special machine has been invented to detect mines. We assume the fields which need to be detected are configuration as several continuous grids, and there is at most one mine in each grid (See Fig a).
Fig a Fig b
When using the machine to detect the ith grid, the machine will provide the number xi, which means the total number of mines in the ith, (i-1)th and (i+1)th grids. Except the first and last grid, the detect result of the first grid is the number of 1st and 2nd grid, and the result of the last grid is the last and the last but two grids. The approximate detect result for Fig a is as Fig b. However, some of these machines may have bugs and provide unreal result. For example, one of the unreal detect result for Fig a is as Fig c. The red grid is unreal result.
Fig c
It is clearly that Fig b is possible result, but Fig c is not. Now, give you the detect result for a given field, please calculate if this result is possible.
输入格式
The first line of input is an integer T (T <= 100), indicate the number of test cases.
Each test case contains two lines.
The first line of each test case is an integer N (3 <= N <= 1000), indicate the length of the given field. The second line contains N integers Xi (0 <= Xi <= 3), each Xi indicate the detect result for grid i.
输出格式
If the detect result is possible, please output “YES”, otherwise, output “NO”.
输入样例
3
13
1 1 1 1 1 1 1 1 1 0 1 2 2
13
1 1 1 1 1 2 1 1 1 0 1 2 2
7
1 2 3 3 3 2 1
输出样例
YES
NO
YES
思路:模拟, 枚举第一个数管辖范围可能的情况, 那么考虑第2 到 第 n - 1 个数时,只需确定该数后一个数需要填什么,特别的n同样是只管辖 n 和 n - 1两个范围,需要特殊考虑。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int vis[], fig[];//vis[] = 1表示i处为炸弹,vis[] = -1表示必定没有炸弹
int suc, n;
int calc(int m)
{
int cnt = ;
if(vis[m - ] == ) cnt++;
if(vis[m] == ) cnt++;
return cnt;
}
bool check()
{
for(int i = ; i < n; ++i)
{
int nd = fig[i] - calc(i);
if(nd == ) vis[i + ] = -;
else if(nd == ) vis[i + ] = ;
else return false;
}
int nd = calc(n);
if(nd == fig[n]) return true;
else return false;
}
int main()
{
// freopen("in.txt","r",stdin);
int _;
scanf("%d",&_);
while(_--)
{
memset(vis, , sizeof vis);
scanf("%d",&n);
for(int i = ; i <= n; ++i) scanf("%d",&fig[i]);
suc = ;
if(fig[] == ) {
vis[] = , vis[] = -;
if(check()) suc = ;
if(!suc) {
vis[] = -, vis[] = ;
if(check()) suc = ;
}
}
else if(fig[] == ) {
vis[] = vis[] = ;
if(check()) suc = ;
}
else if(fig[] == ) {
vis[] = vis[] = -;
if(check()) suc = ;
}
else suc = ;
if(suc) printf("YES\n");
else printf("NO\n");
}
}
8659 Mine Sweeping的更多相关文章
- TOJ 3184 Mine sweeping
描述 I think most of you are using system named of xp or vista or win7.And these system is consist of ...
- 【HDOJ】3316 Mine sweeping
简单BFS. #include <iostream> #include <cstdio> #include <cstring> #include <cstdl ...
- Mine Number(搜索,暴力) ACM省赛第三届 G
Mine Number Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Every one once played the gam ...
- [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number
Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...
- C language 模拟 win的经典游戏——扫雷
让我们在terminal下愉快的...扫雷 昨天跟奇葩霖聊起"雷区"这个敏感词汇,然后非常荣幸的... 应该轰炸不到我.. . 后来百无聊赖的去玩了把扫雷.然后发现我之前都是乱扫的 ...
- SVN版本冲突,导致出现Files 的值“ < < < < < < < .mine”无效
只要根据错误提示,找到相应文件夹下的\obj\Debug文件夹下的 相应名字.csproj.FileListAbsolute.txt, 打开并删除含有'<<<<<< ...
- Files 的值“<<<<<<< .mine”无效。路径中具有非法字符
解决冲突,告诉SVN这个问题已解决(Resolved). 一般更简单些:在你的工程OBJ/DEBUG目录下,找到 工程名.csproj.FileListAbsolute.txt的文件打开并删除含有'& ...
- SVN Files 的值“ < < < < < < < .mine”无效。路径中具有非法字符。
错误 1 Files 的值“ < < < < < < < .mine”无效.路径中具有非法字符. 今天使用SVN进行更新的时候,出现了如上问题,想起卓 ...
- Files 的值“ < < < < < < < .mine”无效。路径中具有非法字符。
出现这个问题的原因是,用svn时,发生了冲突.解决方法:先解决代码冲突,然后在你的工程OBJ/DEBUG目录下,找到 工程名.csproj.FileListAbsolute.txt的文件打开并删除含有 ...
随机推荐
- UIButton 的点击事件详解
UIControlEventTouchDown 单点触摸按下事件:用户点触屏幕,或者又有新手指落下的时候. UIControlEventTouchDownRepeat 多点触摸按下事件,点触计数大于1 ...
- Split()的简单的用法
1.Split分割一些简答的字符串事例: string str="aaa|bbb|ccc"; string[] list = str.Split('|'); 这是一个字符的切割,但 ...
- MyBatis之多表关联查询
1使用resultType.ResultMap处理返回结果 处理返回结果 resultType:指定返回值结果的完全限定名,处理多表查询的结果. 多表查询需要定义vo封装查询的结果. 需求:查询部门和 ...
- ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(九) 之 用 Redis 实现用户在线离线状态消息处理(一)
前言 上一篇中简单讲解了用Redis缓存在线用户逻辑.篇幅也比较小,本篇将详细实现用户的上线下线通知.图片效果转换功能.而且,代码和开发思路都会详细介绍. 效果展示 目前有三个用户,user1,use ...
- Mysql 分区
关于分区操作,可参考:http://lobert.iteye.com/blog/1955841 这篇文章写的还是比较全面的. 关于Linear hash说明,可参考:http://www.bug315 ...
- Git 操作的一些场景
1. 某些不需要的文件/文件夹,如:/build 之类,在添加对应的gitignore之前Push了,导致每次编译都会产生新的文件 解决方法:直接删掉不需要的文件/文件夹,然后push gitigno ...
- hadoop2.x NameNode 的共享存储实现
过去几年中 Hadoop 社区涌现过很多的 NameNode 共享存储方案, 比如 shared NAS+NFS.BookKeeper.BackupNode 和 QJM(Quorum Journal ...
- 四、优化及调试--网站优化--Yahoo军规下
21.根据域名划分页面内容 很显然, 是最大限度地实现平行下载 22.尽量减少iframe的个数 考虑即使内容为空,加载也需要时间,会阻止页面加载,没有语意,注意iframe相对于其他DOM元素高出1 ...
- Arch Linux 安装、配置、美化和优化
国庆假期玩了下Arch Linux,发现这货跟Ubuntu之流相差甚远,甚难调教,而且安裝过程全命令行,会有各种问题,各种知识... --- 安装引导器--- -------------------- ...
- 实现VS2010整合NUnit进行单元测试(转载)
代码编写,单元测试必不可少,简单谈谈Nunit进行单元测试的使用方式: 1.下载安装NUnit(最新win版本为NUnit-2.6.4.msi) http://www.nunit.org/index. ...