版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/C_13579/article/details/81978756
地址:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1997
思路:对于 1-n 稍微推一下就可以知道最优排列方式为 中间值h=(n+1)/2与最大值r=n 依次减小交叉排列
例如 n=6,则为 3 6 2 5 1 4 n=7则为 4 7 3 6 2 5 1
那么其最大差值 t=n/2,则 d>=t就为 -1
Code :
#include<iostream>
using namespace std;
int n,d;
int main()
{
ios::sync_with_stdio(false);
while(cin>>n>>d){
int t=n/2;
if(d<t){
int l=(n+1)/2,r=n;
for(int i=0;i<n;++i)
{
if(i) cout<<" ";
if(i%2==0) cout<<l--;
else cout<<r--;
}
cout<<endl;
}else cout<<-1<<endl;
}
return 0;
}