题解 | 构造数列

构造数列

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

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll = long long;
#define int long long
#define db double
#define all(a) a.begin(), a.end()
const int M = 5e3 + 7;
const int mod = 100003;
const double pi = acos(-1.0);
int n, m, k, h;
void solve()
{
    cin >> n;
    if (n == 2)
    {
        cout << "NO" << endl;
        return;
    }
    int a = n / 2;
    if (a % 2 == 1)
    {
        cout << "NO" << endl;
        return;
    }
    cout << "YES" << endl;
    h = 0;
    for (int i = 1; i <= n / 2; i++)
    {
        cout << 2 * i << ' ';
        h += 2 * i;
    }
    k = 0, m = 0;
    for (int i = 1;; i += 2)
    {
        if (k == n / 2 - 1)
        {
            cout << h - m << endl;
            break;
        }
        cout << i << ' ';
        k++, m += i;
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int qwq = 1;
    cin >> qwq;
    while (qwq--)
    {
        solve();
    }
    return 0;
}

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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