B-Build the Permutation
Posted karshey
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了B-Build the Permutation相关的知识,希望对你有一定的参考价值。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define pb push_back
#define fi first
#define se second
#define mem(a,x) memset(a,x,sizeof(a));
#define db double
#define fir(i,a,n) for(int i=a;i<=n;i++)
#define debug(x) cout<<#x<<" "<<x<<endl;
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const double pi=acos(-1.0);
//======================
const int N=1e5+10;
int a[N];
int main()
int t;scanf("%d",&t);
while(t--)
int n,tu,ou;
scanf("%d%d%d",&n,&tu,&ou);
if(abs(tu-ou)>1)
cout<<-1<<endl;
continue;
if(n==2)
if(ou==0&&tu==0)
cout<<1<<" "<<2<<endl;
continue;
else
cout<<-1<<endl;
continue;
if(tu==ou)
if(tu>n/2-1)
cout<<-1<<endl;
continue;
else
if(n%2==1&&max(tu,ou)>n/2)//!!!!!!!!!
cout<<-1<<endl;
continue;
if(n%2==0&&max(tu,ou)>n/2-1)
cout<<-1<<endl;
continue;
int xiao=min(tu,ou);
int da;//凸大为1
if(tu>ou) da=1;
else if(tu<ou) da=-1;
else da=0;
for(int i=1;i<=n;i++) a[i]=i;
if(da==1)//凸
swap(a[n],a[n-1]);
for(int i=2;i<=n-2;i+=2)
if(xiao)
swap(a[i],a[i+1]);
xiao--;
else break;
else if(da==-1)//凹
swap(a[1],a[2]);
for(int i=3;i<=n-1;i+=2)
if(xiao)
swap(a[i],a[i+1]);
xiao--;
else break;
else//==
for(int i=2;i<=n-1;i+=2)
if(xiao)
swap(a[i],a[i+1]);
xiao--;
else break;
for(int i=1;i<=n;i++)
cout<<a[i]<<" ";
cout<<endl;
/*
3
4 1 1
6 1 2
6 4 0
*/
以上是关于B-Build the Permutation的主要内容,如果未能解决你的问题,请参考以下文章
CodeForces 618B Guess the Permutation
codeforces Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) B Guess the Permutation
Uva 11077 Find the Permutation
The 2019 China Collegiate Programming Contest Harbin Site I. Interesting Permutation
1. PermMissingElem Find the missing element in a given permutation.