其他分享
首页 > 其他分享> > 5.23 Vj B - Balanced Array

5.23 Vj B - Balanced Array

作者:互联网

#include<bits/stdc++.h>
#define ll long long
using namespace std;
//按照题意可知二分之n为偶数的时候存在这样的数组,按照题意分两部分存入数组即可
int main()
{
    ll t,n;
    cin>>t;
    for(int i=0; i<t; i++)
    {
        cin>>n;
        if(n/2%2==0)
        {
            ll a[n+1];
            ll s=0,k=1;
            for(int j=1; j<=n/2; j++)
            {
                a[j]=j*2;
                s+=a[j];
            }
            for(int j=n/2+1;j<n;j++)
            {
                a[j]=k;
                s-=k;
                k+=2;
            }
            a[n]=s;
            cout<<"YES"<<endl;
            for(int j=1;j<=n;j++)
            {
                cout<<a[j]<<" ";
            }
            cout<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
}

标签:cout,int,Vj,cin,5.23,数组,Balanced,ll,题意
来源: https://www.cnblogs.com/SyrupWRLD999/p/12941475.html