Codeforces Round #636 B. Balanced Array(水)
You are given a positive integer nn , it is guaranteed that nn is even (i.e. divisible by 22 ).
You want to construct the array aa of length nn such that:
- The first n2n2 elements of aa are even (divisible by 22 );
- the second n2n2 elements of aa are odd (not divisible by 22 );
- all elements of aa are distinct and positive;
- the sum of the first half equals to the sum of the second half (∑i=1n2ai=∑i=n2+1nai∑i=1n2ai=∑i=n2+1nai ).
If there are multiple answers, you can print any. It is not guaranteed that the answer exists.
You have to answer tt independent test cases.
The first line of the input contains one integer tt (1≤t≤1041≤t≤104 ) — the number of test cases. Then tt test cases follow.
The only line of the test case contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105 ) — the length of the array. It is guaranteed that that nn is even (i.e. divisible by 22 ).
It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105 (∑n≤2⋅105∑n≤2⋅105 ).
For each test case, print the answer — "NO" (without quotes), if there is no suitable answer for the given test case or "YES" in the first line and any suitable array a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109 ) satisfying conditions from the problem statement on the second line.
5 2 4 6 8 10
NO YES 2 4 1 5 NO YES 2 4 6 8 1 3 5 11 NO
随便构造构造。。。注意:当n/2为奇数时是不行的,因为前半部分和是偶数后半部分是奇数必不可能相等。
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n; cin>>n; if((n/2)%2!=0) { cout<<"NO"<<endl; continue; } cout<<"YES"<<endl; vector<int>v1,v2; int i; for(i=1;i<=n/2;i++)v1.push_back(i*2); for(i=1;i<=n/2-1;i++)v2.push_back(i*2-1); v2.push_back(n/2+2*n/2-1); for(i=0;i<v1.size();i++)cout<<v1[i]<<' '; for(i=0;i<v2.size();i++)cout<<v2[i]<<' '; cout<<endl; } return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!