时间限制: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”.

输入样例

  1. 3
  2. 13
  3. 1 1 1 1 1 1 1 1 1 0 1 2 2
  4. 13
  5. 1 1 1 1 1 2 1 1 1 0 1 2 2
  6. 7
  7. 1 2 3 3 3 2 1

输出样例

  1. YES
  2. NO
  3. YES
    思路:模拟, 枚举第一个数管辖范围可能的情况, 那么考虑第2 n - 1 个数时,只需确定该数后一个数需要填什么,特别的n同样是只管辖 n n - 1两个范围,需要特殊考虑。
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <queue>
  6. using namespace std;
  7. int vis[], fig[];//vis[] = 1表示i处为炸弹,vis[] = -1表示必定没有炸弹
  8. int suc, n;
  9. int calc(int m)
  10. {
  11. int cnt = ;
  12. if(vis[m - ] == ) cnt++;
  13. if(vis[m] == ) cnt++;
  14. return cnt;
  15. }
  16. bool check()
  17. {
  18. for(int i = ; i < n; ++i)
  19. {
  20. int nd = fig[i] - calc(i);
  21. if(nd == ) vis[i + ] = -;
  22. else if(nd == ) vis[i + ] = ;
  23. else return false;
  24. }
  25. int nd = calc(n);
  26. if(nd == fig[n]) return true;
  27. else return false;
  28. }
  29. int main()
  30. {
  31. // freopen("in.txt","r",stdin);
  32. int _;
  33. scanf("%d",&_);
  34. while(_--)
  35. {
  36. memset(vis, , sizeof vis);
  37. scanf("%d",&n);
  38. for(int i = ; i <= n; ++i) scanf("%d",&fig[i]);
  39. suc = ;
  40. if(fig[] == ) {
  41. vis[] = , vis[] = -;
  42. if(check()) suc = ;
  43. if(!suc) {
  44. vis[] = -, vis[] = ;
  45. if(check()) suc = ;
  46. }
  47. }
  48. else if(fig[] == ) {
  49. vis[] = vis[] = ;
  50. if(check()) suc = ;
  51. }
  52. else if(fig[] == ) {
  53. vis[] = vis[] = -;
  54. if(check()) suc = ;
  55. }
  56. else suc = ;
  57. if(suc) printf("YES\n");
  58. else printf("NO\n");
  59. }
  60. }

8659 Mine Sweeping的更多相关文章

  1. 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 ...

  2. 【HDOJ】3316 Mine sweeping

    简单BFS. #include <iostream> #include <cstdio> #include <cstring> #include <cstdl ...

  3. Mine Number(搜索,暴力) ACM省赛第三届 G

    Mine Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Every one once played the gam ...

  4. [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number

    Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...

  5. C language 模拟 win的经典游戏——扫雷

    让我们在terminal下愉快的...扫雷 昨天跟奇葩霖聊起"雷区"这个敏感词汇,然后非常荣幸的... 应该轰炸不到我.. . 后来百无聊赖的去玩了把扫雷.然后发现我之前都是乱扫的 ...

  6. SVN版本冲突,导致出现Files 的值“ < < < < < < < .mine”无效

    只要根据错误提示,找到相应文件夹下的\obj\Debug文件夹下的 相应名字.csproj.FileListAbsolute.txt, 打开并删除含有'<<<<<< ...

  7. Files 的值“<<<<<<< .mine”无效。路径中具有非法字符

    解决冲突,告诉SVN这个问题已解决(Resolved). 一般更简单些:在你的工程OBJ/DEBUG目录下,找到 工程名.csproj.FileListAbsolute.txt的文件打开并删除含有'& ...

  8. SVN Files 的值“ < < < < < < < .mine”无效。路径中具有非法字符。

    错误 1 Files 的值“ < < < < < < < .mine”无效.路径中具有非法字符.     今天使用SVN进行更新的时候,出现了如上问题,想起卓 ...

  9. Files 的值“ < < < < < < < .mine”无效。路径中具有非法字符。

    出现这个问题的原因是,用svn时,发生了冲突.解决方法:先解决代码冲突,然后在你的工程OBJ/DEBUG目录下,找到 工程名.csproj.FileListAbsolute.txt的文件打开并删除含有 ...

随机推荐

  1. python MethodType方法详解和使用

    python 中MethodType方法详解和使用 废话不多说,直接上代码 #!/usr/bin/python # -*-coding:utf-8-*- from types import Metho ...

  2. iOS添加另一个控制器的时候要注意啊

    ios的父控制器控制器和子控制器之间的注意点: " >> #warning 需要把新创建出来的控制器添加成子控制器 . 不然子控制器里面的子控件无法响应点击事件 " 一 ...

  3. C#冒泡排序

    C#最简单的冒泡排序,需要的朋友可作参考: 思路: 使用两个for循环,就可以遍历数组,这样就可以确保每个数组元素都被使用 对比前后两个数,将小的数字和大的交换位置,引入一个临时变量temp来进行交换 ...

  4. wireshark_Couldn’t run /usr/sbin/dumpcap in child process: Permission denied

    关于Wireshark出现:Couldn't run /usr/sbin/dumpcap in child process: Permission denied Are you a member of ...

  5. 二、JavaScript语言--事件处理--DOM事件探秘--下拉菜单

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. linux命令**50

    1.ls命令 命令格式: ls [选项] [目录名] 命令功能: 列出目标目录中所有的子目录和文件. 常用参数: -a,列出所有文件包括隐藏文件 -l,列出详细信息,文件大小一般以字节大小显示 -h, ...

  7. SQL分组和聚合(Grouping and Aggregates)

    这章应该是难点,也是成为SQL高手的必经之路. 注意有GROUP 语句时,WHERE和HAVING的场合. 前者用于检索前的条件过滤 . 后者用于检索出来结果之后的条件过滤. ========== ; ...

  8. git revert 和 git reset的区别

    git revert 撤销 某次操作,此次操作之前和之后的commit和history都会保留,并且把这次撤销 作为一次最新的提交    * git revert HEAD               ...

  9. Linux环境下stl库使用(vector)

    step1: #include <iostream> #include <vector> #include <string> using namespace std ...

  10. bootstrap表单带验证

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...