Magical Bamboos Gym

来源:互联网 发布:猪年春晚不提猪 知乎 编辑:程序博客网 时间:2024/06/06 01:32

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
232 4 221 2
Output
yesno

就是找规律呗,自己写几组数就找到规律了

排序后不能有两个相邻的差为1或者差对二取余不为零

#include <iostream>#include <algorithm>#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <string.h>#include <map>#include <set>#include <queue>#include <deque>#include <list>#include <bitset>#include <stack>#include <stdlib.h>#define lowbit(x) (x&-x)using namespace std;int a[100005];int main(){    int t;    cin>>t;    while(t--)    {        memset(a,0,sizeof(a));        int n;        cin>>n;        for(int i=0;i<n;i++)            scanf("%d",&a[i]);        sort(a,a+n);        int flag = 1;        for(int i=1;i<n;i++)        {            //cout<<a[i]<<endl;            if((a[i]-a[i-1]==1)||(a[i]-a[i-1])%2!=0)            {                flag = 0;                cout<<"no"<<endl;                break;            }        }        if(flag)            cout<<"yes"<<endl;    }    return 0;}



0 0