思路大概是先让第一层布满 n-1 个节点,之后依次向下“放点”,大概就是距离+=放到下一层的点数
思路是假了吗,subtask0,1全WA,测试点 36-43 WA
code
#include<iostream>
#include<cstring>
#define int long long
using namespace std;
int n,d,k,t;
int dep[1000005];
signed main()
{
cin>>t;
while(t--)
{
cin>>n>>d>>k;
for(int i=1;i<=2*n;i++) dep[i]=0;
if(d<n-1||(n==1&&d!=0))
{
cout<<"NO"<<endl;
continue;
}
if(n==1&&d==0)
{
cout<<"YES"<<endl;
cout<<endl;
continue;
}
int last=1;dep[0]=1;dep[1]=n-1;
int dis=n-1,t=1;
int flag=0;
while(dis!=d)
{
if(dep[t]-k<0)
{
flag=1;
break;
}
if(d-dis>dep[t]-k)
{
dep[t+1]=dep[t]-k;
dis+=(dep[t]-k);
dep[t]=k;
++t;
}
else
{
dep[t+1]=d-dis;
dep[t]-=dep[t+1];
dis=d;
if(dep[t+1]<k)
{
dep[t]-=2*(k-dep[t+1]);
if(dep[t]<k)
{
flag=1;
break;
}
dep[t-1]+=(k-dep[t+1]);
dep[t+1]=k;
}
++t;
}
if(dep[t]-k<0)
{
flag=1;
break;
}
}
if(flag)
{
cout<<"NO"<<endl;
continue;
}
cout<<"YES"<<endl;
for(int i=1;i<=t;i++)
{
for(int j=1;j<=dep[i];j++) cout<<last<<' ';
last+=dep[i];
}
cout<<endl;
}
return 0;
}