码迷,mamicode.com
首页 > 其他好文 > 详细

水题(规律)

时间:2019-08-02 20:44:55      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:line   pos   gic   i++   this   判断   cond   ssi   das   

D - AYAYAYA

Gym - 101350D

In a magical forest, there exists N bamboos that don‘t quite get cut down the way you would expect.

Originally, the height of the ith bamboo is equal to hi. In one move, you can push down a bamboo and decrease its height by one, but this move magically causes all the other bamboos to increase in height by one.

If you can do as many moves as you like, is it possible to make all the bamboos have the same height?


Input

The first line of input is T – the number of test cases.

The first line of each test case contains an integer N (1 ≤ N ≤ 105) - the number of bamboos.

The second line contains N space-separated integers hi (1 ≤ hi ≤ 105) - the original heights of the bamboos.

Output

For each test case, output on a single line "yes” (without quotes), if you can make all the bamboos have the same height, and "no" otherwise.

Example
Input
2
3
2 4 2
2
1 2
Output
yes
no
思路:判断是否全为奇或偶
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include <stdio.h>
#include <string.h>
using namespace std;
const int N = 1000009 ;
int a[100009] ;

int main()
{
    int n ;
    cin >> n ;
    while(n--)
    {
        int m ;
        scanf("%d" , &m);
        int sum = 0 ;
        for(int i = 0 ; i < m ; i++)
        {
            scanf("%d" , &a[i]);
        }
        int flag = 1 ;
        if(m == 1)
            printf("yes\n");
        else
        {
            for(int i = 1 ; i < m ; i++)
            {
                if((a[i] - a[i - 1])%2 != 0)
                {
                    flag = 0 ;
                    break;
                }
            }
            if(flag)
                printf("yes\n");
            else
                printf("no\n");
        }
    }



    return 0 ;
}

 

 

水题(规律)

标签:line   pos   gic   i++   this   判断   cond   ssi   das   

原文地址:https://www.cnblogs.com/nonames/p/11290742.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!