zoukankan      html  css  js  c++  java
  • Magical Bamboos

    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

    Copy

    2
    3
    2 4 2
    2
    1 2
    

    output

    Copy

    yes
    no
    <span style="color:#880000">题意:每次找最大的数减一,其他的数加一,要是每个数相等,就YES。规律是每个数相差偶数就YES</span>
    #include <iostream>
    #include <stdio.h>
    #include <algorithm>
    using namespace std;
    bool cmp(int a,int b)
    {
        return a>b;
    }
    int main()
    {
        int t,n,i,x,s,a[100000];
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            for(i=0;i<n;i++)
            {
                scanf("%d",&a[i]);
            }
            sort(a,a+n,cmp);
            for(i=1;i<n;i++)
            {
                if((a[i]-a[i-1])%2!=0)
                    break;
            }
            if(i==n)
                printf("yes
    ");
            else
                printf("no
    ");
        }
        return 0;
    }
    
     
  • 相关阅读:
    洛谷 P2029 跳舞
    洛谷 P1122 最大子树和
    洛谷 P2015 二叉苹果树
    洛谷 P1651 塔
    洛谷 P1759 通天之潜水
    洛谷 P2763 试题库问题
    洛谷 P2364 胖男孩
    <转>jmeter(十四)HTTP请求之content-type
    <转>jmeter(十三)常见问题及解决方法
    <转>jmeter(十二)关联之正则表达式提取器
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702815.html
Copyright © 2011-2022 走看看