0
点赞
收藏
分享

微信扫一扫

codeforces - 1315C - 思维题

原题链接:https://codeforces.com/problemset/problem/1315/C

翻译:

代码实现:

 

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t,n,j;
    cin >> t;
    for(int i=0; i<t; i++){
        int a[222]={0},b[222]={0};
        for(j=1; j <= 200; j++){
            b[j]=j;
        }
        scanf("%d",&n);
        for(int j=1; j <= 2*n; j=j+2){
            scanf("%d",&a[j]);
            b[a[j]]=0;
        }
        for(j=2; j <= 2*n; j=j+2){
            for(int k=1; k<=2*n; k++){
                if(b[k] != 0 && b[k] > a[j-1]){
                    a[j] = b[k];
                    b[a[j]] = 0;
                    break;
                }
            }
        }
        for(j=1; j<=2*n; j=j+2){
            if(a[j] < a[j+1]){
                continue;
            }
            else{
                break;
            }
        }
        if(j > 2*n){
            for(j=1; j<=2*n; j++){
                printf("%d ",a[j]);
            }
        }
        else{
            printf("-1");
        }
        printf("\n");
    }
    return 0;
}
举报

相关推荐

0 条评论