2025-11-25

CF

构造(1300)

Problem - 1864C - Codeforces(lowbit)

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=2e5+10;
int lowbit(int x){
    return x & (-x);
}

void solve()
{
    int n;
    cin >> n;
    vector<int> v;
    v.push_back(n);
    while(n!=lowbit(n)){
        int x = lowbit(n);
        n -= x;
        v.push_back(n);
    }
    while(n!=1){
        n /= 2;
        v.push_back(n);
    }
    cout << v.size() << endl;
    for(auto i:v){
        cout << i << " ";
    }
    cout << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
}

Problem - 1788C - Codeforces

不会证明的构造题

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=2e5+10;

void solve()
{
    int n;
    cin >> n;
    if(n%2==0){
        cout << "NO\n";
        return;
    }
    cout << "YES\n";
    for (int i = 1; i <= n;i+=2){
        cout << i << " " << 2 * n - i / 2 << endl;
    }
    for (int i = n-1,j=1; i >=2;i-=2,j++){
        cout << i << " " << n +j<<endl;
    }
}
/*
(n+1)8 9 10 | 11 12 13 14(2n)
(n-1)6 4 2  | 7  5  3  1(1)
*/

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
}
posted @ 2025-11-25 23:33  Seren_blingbling  阅读(4)  评论(0)    收藏  举报