C. Restoring Permutation

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

You are given a sequence b1,b2,…,bn. Find the lexicographically minimal permutation a1,a2,…,a2n such that bi=min(a2i−1,a2i), or determine that it is impossible.

Input

Each test contains one or more test cases. The first line contains the number of test cases t (1≤t≤100).

The first line of each test case consists of one integer n — the number of elements in the sequence b (1≤n≤100).

The second line of each test case consists of n different integers b1,…,bn — elements of the sequence b (1≤bi≤2n).

It is guaranteed that the sum of n by all test cases doesn’t exceed 100.

Output

For each test case, if there is no appropriate permutation, print one number −1.

Otherwise, print 2n integers a1,…,a2n — required lexicographically minimal permutation of numbers from 1 to 2n.

Example

inputCopy

5

1

1

2

4 1

3

4 1 3

4

2 3 4 5

5

1 5 7 2 8

outputCopy

1 2

-1

4 5 1 2 3 6

-1

1 3 5 6 7 9 2 4 8 10

暴力暴力,

#include <bits/stdc++.h>
using namespace std; int a[1000], b[1000], n, t;
bool vis[1000];
void solve()
{
bool r=1;
for (int i = 1; i <= n; ++i)
{
b[2 * i - 1] = a[i];
r = 1;
for (int j = a[i]; j <= 2 * n; ++j)
if (!vis[j])
{
b[2 * i] = j;
vis[j] = 1;
r = 0;
break;
}
if (r == 1)
break;
}
r = 1;
for (int i = 1; i <= 2 * n; ++i)
if (b[i] == 0)
{
r = 0;
break;
}
if (r == 0)
puts("-1");
else
{
for (int i = 1; i <= 2 * n; ++i)
cout << b[i] << ' ';
cout << endl;
}
}
int main()
{
cin >> t;
while (t--)
{
memset(vis, 0, sizeof vis);
memset(b, 0, sizeof b);
cin >> n;
bool r = 1;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
vis[a[i]] = 1;
if (a[i] == 2 * n)
r = 0;
}
if (r == 0) puts("-1");
else
solve();
}
}

Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) C. Restoring的更多相关文章

  1. Codeforces Round 623(Div. 2,based on VK Cup 2019-2020 - Elimination Round,Engine)D. Recommendations

    VK news recommendation system daily selects interesting publications of one of n disjoint categories ...

  2. Codeforces Round #623 (Div. 1, based on VK Cup 2019-2020 - Elimination Round, Engine)A(模拟,并查集)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; pair<]; bool cmp( ...

  3. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine)

    A. Dead Pixel(思路) 思路 题意:给我们一个m*n的表格,又给了我们表格中的一个点a,其坐标为(x, y),问在这个表格中选择一个不包括改点a的最大面积的矩形,输出这个最大面积 分析:很 ...

  4. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) B. Homecoming

    After a long party Petya decided to return home, but he turned out to be at the opposite end of the ...

  5. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) A Dead Pixel

    讨论坏点的左右上下的矩形大小. #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> ...

  6. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)【ABCDF】

    比赛链接:https://codeforces.com/contest/1443 A. Kids Seating 题意 构造一个大小为 \(n\) 的数组使得任意两个数既不互质也不相互整除,要求所有数 ...

  7. Codeforces Round #681 (Div. 1, based on VK Cup 2019-2020 - Final) B. Identify the Operations (模拟,双向链表)

    题意:给你一组不重复的序列\(a\),每次可以选择一个数删除它左边或右边的一个数,并将选择的数append到数组\(b\)中,现在给你数组\(b\),问有多少种方案数得到\(b\). 题解:我们可以记 ...

  8. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) D. Extreme Subtraction (贪心)

    题意:有一个长度为\(n\)的序列,可以任意取\(k(1\le k\le n)\),对序列前\(k\)项或者后\(k\)减\(1\),可以进行任意次操作,问是否可以使所有元素都变成\(0\). 题解: ...

  9. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) C. The Delivery Dilemma (贪心,结构体排序)

    题意:你要买\(n\)份午饭,你可以选择自己去买,或者叫外卖,每份午饭\(i\)自己去买需要消耗时间\(b_i\),叫外卖需要\(a_i\),外卖可以同时送,自己只能买完一份后回家再去买下一份,问最少 ...

随机推荐

  1. iOS岗位招聘标准水涨船高,五年iOS程序员表示面试太难了

    人才济济的iOS开发者,你凭什么脱颖而出? 与岗位要求相去甚远,如何挑战极限? 想去心怡公司,如何马到成功? 那么,你的绝招是什么呢? 在这个iOS岗位供不应求的市场,对iOS开发者对要求日益增长,面 ...

  2. "格式化的文本"组件:<span> —— 快应用原生组件

     `<template> <div class="container"> <text><span class="success ...

  3. AJ学IOS(27)UI之iOSUIKit字符属性NSAttributedString概述

    AJ分享,必须精品 UIKit字符属性NSAttributedString概述 字符属性 字符属性可以应用于 attributed string 的文本中. NSString *const NSFon ...

  4. TCP的分分合合(面试必问)

    TCP连接与断开 目录 TCP连接与断开 前言 握手 挥手 最后 前言 相信面试过的小伙伴对这个话题应该不陌生,算是面试必问了,三次握手,四次挥手,以及其中的一些衍生问题. TCP/IP(Transm ...

  5. G - Can you find it? 二分

    Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...

  6. linux sysbench : CPU性能测试详解

    1.sysbench基础知识 sysbench的cpu测试是在指定时间内,循环进行素数计算 素数(也叫质数)就是从1开始的自然数中,无法被整除的数,比如2.3.5.7.11.13.17等.编程公式:对 ...

  7. 零基础的学习者应该怎么开始学习呢?Python核心知识学习思维分享

    近几年,Python一路高歌猛进,成为最受欢迎的编程语言之一,受到无数编程工作者的青睐. 据悉,Python已经入驻部分小学生教材,可以预见学习Python将成为一项提高自身职业竞争力的必修课.那么零 ...

  8. vue如何添加jquery?

    1.首选通过npm安装jquery? 2.在build/webpack.base.conf文件当中引入jquery <pre>module.exports = { ... resolve: ...

  9. 编码理解的漫漫长路(Unicode、GBK、ISO)

    Ø 那么现在开始康康都有哪些编码方式  1.  ASCII

  10. [PHP] excel 的导入导出

    其实excel导入导出挺简单的,导出最简单! 其原理都是把数据读出来,导出是从数据库中读出数据,导入是从文件读出数据! 导出写入文件,导入写入数据库! 但是在导入表的时候,用的是PHPExcel, 不 ...