Mine Sweeping

描述

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

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.
在这里插入图片描述
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

简单的模拟扫雷,问你是否存在合理的炸弹摆放位置输出YES或者NO
首先先举例摆放第一个位置是否放置炸弹,后一个位置放置炸弹跟前一个位置是有关系的,一直推倒最后一个位置,我们还得判断最后一个位置是否符合条件。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 1001
int num[N],x[N],flag;
int main(){
    int t,n;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);

        for(int i=1;i<=n;i++)
            scanf("%d",&num[i]);

        for(int i=0;i<=1;i++){
           flag=1;
           x[1]=i;
           for(int j=2;j<=n;j++){
                x[j]=num[j-1]-x[j-1]-x[j-2];
                if(x[j]>1||x[j]<0){
                    flag=0;break;
                }
            }
            if(flag){//如果推倒最后一个也是成立的才能跳出,否则就继续循环
                if(num[n]==x[n]+x[n-1]) break;
            }
        }
        if(num[n]!=x[n]+x[n-1])flag=0;
        if(flag)printf("YES\n");
        else printf("NO\n");
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值