题解 | 构造数列

构造数列

https://www.nowcoder.com/practice/392c2659f7c34cebb37b921342dd39ea

#include <iostream>
using namespace std;

void solve(){
    int n;cin>>n;
    if(n/2%2==1)cout<<"NO"<<endl;//如果n/2是奇数,奇数个奇数还是奇数,奇数个偶数是偶数,一定不相等。
    else {
        cout<<"YES"<<endl;
        int sum=0,num=0;
        for(int i=1,j=2;i<=n/2;i++,j+=2){
            cout<<j<<" ";
            sum+=j;
        }
        for(int i=1,j=1;i<n/2;i++,j+=2){
            cout<<j<<" ";
            num+=j;
        }cout<<sum-num<<endl;
    }
}
int main() {
    int t;cin>>t;
    while (t--){
        solve();
    }return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

2025-12-28 22:19
门头沟学院 Java
不敢追165女神:简历写得毫无特点,你说你要是大二或者大三找寒假实习到暑期实习这段时间,你的简历还能约到面试。但是你是研究生哥,面试官不会因为你是研究生而降低要求,反而会觉得你是研究生才学了这么一点?为什么我不找个同阶段的本科生?
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务