D-Magical Bamboos

https://codeforces.com/gym/323862/problem/D
选择一个减小1,其他的都增加1,可以看做其他是不变的,而这个数减小了2,所以必须奇偶性相同

    #include
    #include 
    #include
    using namespace std;
    const int maxn = 1e5+10;
    int n,a[maxn];
    int main()
    {
     
        ios::sync_with_stdio(0);
        int t;
        cin>>t;
        while (t--){
     
            cin>>n;
            for(int i = 1;i <= n;++i)
                cin>>a[i];
            bool flag = 0;
            sort(a+1,a+1+n);
            for(int i = 1;i < n;++i)
            {
     
                int k = a[i+1]- a[i];
                if(k%2 == 1)
                {
     
                    flag = 1;
                    break;
                }
            }
            if(!flag) cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
        return 0;
    }

你可能感兴趣的:(思维题)