CSU-ACM暑假集训基础组七夕专场 F - Problem F

F - Problem F
Time Limit:500MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

Suppose we have a sequence of non-negative integers, Namely a1, a2, ... ,an. At each time we can choose one term ai with 0 < i < n and we subtract 1 from both ai and ai+1. We wonder whether we can get a sequence of all zeros after several operations.

Input

The first line is the number of test cases T ( 0 < T <= 20).

The first line of each test case is a number N. (0 < N <= 10000) The next line is N non-negative integers, 0 <= ai <= 109

Output

If it can be modified into all zeros with several operations output “YES” in a single line, otherwise output “NO” instead.

Example

Input:
2
2
1 2
2
2 2

Output:
NO
YES

Explanation:

It is clear that [1 2] can be reduced to [0 1] but no further to convert all integers to 0. Hence, the output is NO.

In second case, output is YES as [2 2] can be reduced to [1 1] and then to [0 0] in just two steps.
 
   
 
   
 
   
 
   
模拟题,基础。代码如下:
    
    
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 10010;
int n,a[N];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        //long long s=0;
        int flag=1,i;
        scanf("%d",&n);
        for( i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            //s+=a[i];
        }
        for(i=0;i<n-1;)
        {
            a[i+1]-=a[i];
            if(a[i+1]>0)
            i++;
            else if(a[i+1]==0)
            i=i+2;
            else
            {
                flag=0;
                break;
            }
        }
        if(flag&&a[n-1]==0) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值