CF1978C-rk1300-1.5h
一道构造题,我的做法似乎思维复杂度上远高于答案的做法,因而不是什么好做法,但幸好我最后还是调出来了,另外就是会爆ll...下意识写int的我根本想不起来用ll啊,看来不得不define int long long了
Code
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#define int long long
using namespace std;
int n,m,k,fk;
void change(int rest_k,int pos)
{
if(pos>n/2&&rest_k>0)
{
cout<<"NO"<<endl;
return;
}
if(rest_k-(n-pos-(pos-1))>0)change(rest_k-(n-pos-(pos-1)),pos+1);
else
{
//int p=1,ans=0;
cout<<"YES"<<endl;
if(rest_k>=1)
{
rest_k+=pos-1;
for(int i=pos+1;i<=pos+1+rest_k-1;i++)
cout<<i<<' ';//,ans+=abs(i-p),p++;
cout<<pos<<' ';//,ans+=abs(pos-p),p++;
for(int i=pos+1+rest_k;i<=n;i++)
cout<<i<<' ';//,ans+=abs(i-p),p++;
}
else
{
for(int i=pos;i<=n;i++)
cout<<i<<' ';//,ans+=abs(i-p),p++;
}
for(int i=pos-1;i>=1;i--)
cout<<i<<' ';//,ans+=abs(i-p),p++;
cout<<endl;//cout<<ans<<endl;if(ans!=fk)cout<<"error"<<endl;
}
}
void solution()
{
cin>>n>>k;
if(k%2==1)cout<<"NO"<<endl;
else
{
fk=k;
k/=2;
change(k,1);
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int T;
cin>>T;
while(T--)
solution();
return 0;
}