繁华模拟赛 Evensgn玩序列

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 5000;
int n,a[maxn],b[maxn],c[maxn],rka[maxn],rkb[maxn],rkc[maxn];
bool visa[maxn],visb[maxn],visc[maxn];
int rk,rec;
int main(){
    freopen("perm.in","r",stdin);
    freopen("perm.out","w",stdout);
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = n;i >= 1;i--){
        cin>>a[i];
        visa[a[i]] = true;
    }
    for(int i = n;i >= 1;i--){
        cin>>b[i];
        visb[b[i]] = true;
    }
    for(int i = n;i >= 1;i--){
        rk = -1;
        for(int j = 0;j <= a[i];j++) if(visa[j]) rk++;
        visa[a[i]] = false;
        rka[i] = rk;
    }
    for(int i = n;i >= 1;i--){
        rk = -1;
        for(int j = 0;j <= b[i];j++) if(visb[j])rk++;
        visb[b[i]] = false;
        rkb[i] = rk;
    }
    for(int i = 1;i <= n;i++){
        rkc[i] += rka[i] + rkb[i];
        rkc[i+1] += rkc[i] / i;
        rkc[i] %= i;
    }
    memset(visc,true,sizeof(visc));
    for(int i = n;i >= 1;i--){
        rec = rk = 0;
        while(1){
            if(visc[rec]) rk++;
            if(rk > rkc[i]) break;
            rec++;
        }
        visc[rec] = false;
        cout<<rec<<" ";
    }
    return 0;
}

 

posted @ 2016-09-24 23:06  ACforever  阅读(499)  评论(0编辑  收藏  举报