题解:P14147 残缺

· · 题解

容易想到这么一种做法:

我们会发现,构造出来的排列如下:

两个都是合法的排列!于是,这题我们就快乐地 AC 了。

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    for(int i=(n+1)/2;i>=0;i--) cout<<i<<' ';
    for(int i=n-1;i>=(n+1)/2+1;i--) cout<<i<<' ';
    return 0;
}