这题的意思是构造三角形,如果n-2==m是一定无法构造的,因为少边,其次只要先从大到小输出满足三角形的个数边,剩下的输出最大值最小值
#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
using namespace std;
const int N = 1e6+10;
int a[N];
signed main() {
IOS
int t;
cin >> t;
while(t--) {
int n,m;
cin>>n>>m;
if(n-m==2)cout<<"-1\n";
else {
int k=n-m;
int t=k;
int id=k/3;
for(int j=0; j<=id; j++)if(j*3+1<=t)a[j*3+1]=k--;
for(int j=0; j<=id; j++)if(j*3+2<=t)a[j*3+2]=k--;
for(int j=id; j>0; j--)a[j*3]=k--;
for(int i=n; i>n-m; i--)cout<<i<<" ";
for(int i=1; i<=t; i++)cout<<a[i]<<" ";
cout<<endl;
}
}
return 0;
}
标签:Haitang,Triangle,cout,int,cin,long,--,define
From: https://blog.csdn.net/dhwujs/article/details/141299536