大佬帮忙看看呗
查看原帖
大佬帮忙看看呗
1272396
huochairenzhishang楼主2024/8/2 19:31
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
const int N = 3;
vector<ll> num(N);
vector<ll> sum(N);
ll max(ll x, ll y){
    return x > y ? x : y;
}
ll min(ll x, ll y){
    return x < y ? x : y;
}
bool cmp(int x, int y){
    return x > y;
}
ll lowbit(ll x){
    return x & -x;
}
ll gcd(ll a, ll b){
    ll r;
    while (b > 0)
    {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}
ll lcm(ll a,ll b){
     return a*b/gcd(a,b);
}
void solve(){

}
int main(){
    int t;cin>>t;
    while(t--){
        int n;ll k;cin>>n>>k;
        if(k%2){
            cout<<"NO"<<'\n';
            continue;
        }
        vector<ll> nn(n+1);
        for(int i=1;i<=n;++i) nn[i]=i;
        for(int i=1;i<=n/2;++i){
            ll ans=2*(nn[n+1-i]-nn[i]);
            if(ans<=k){
                swap(nn[i],nn[n+1-i]);
                k-=ans;
            }else{
                swap(nn[i],nn[i+k/2]);
                k=0;
            }
        }
        if(k!=0){
            cout << "NO" << '\n';
            continue;
        }
        else{
            cout<<"YES"<<'\n';
            for(int i=1;i<=n;++i) cout<<nn[i]<<' ';
            cout<<'\n';
        }
    }
        return 0;
}
2024/8/2 19:31
加载中...