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. 工作中常用的Android系统ADB命令收集

    ​工作中常用的Android系统ADB命令收集如下:先收藏以备以后查阅! ​ adb --help //adb帮助 adb start-server //启动adb server adb kill-s ...

  2. PHP程序员的能力水平层次(二)

    PHPer的定义:PHPer是以PHP程序编写为主要工作,其他方面略有涉及的一种职业人士,大家所说的程序猿. 对PHPer的等级划分 PHP 爱好者 (半个PHPer) PHP 初学者 (PHP Be ...

  3. Go语言的GPM调度器是什么?

    我是平也,这有一个专注Gopher技术成长的开源项目「go home」 导读 相信很多人都听说过Go语言天然支持高并发,原因是内部有协程(goroutine)加持,可以在一个进程中启动成千上万个协程. ...

  4. EXPLAIN 关键字可以 查看 sql执行 的详细过程

    EXPLAIN SELECT n_did,n_count,n_total,d_last_exchange FROM player_con_record WHERE n_roleid=1 AND n_f ...

  5. JDK安装详细步骤

    JDK的下载与安装 在java实际编程的道路上,迈出的第一步必定是JDK的安装,因为JDK是一切java的基础,这里给出在Windows10 x64版本下的JDK1.8的详细安装步骤,其他的Windo ...

  6. 【DataBase】更改root根用户密码 和 SQLyog安装

    更改root根用户密码 和 SQLyog安装 无密码登录MySQL mysql -u root -p 修改密码与更新加密规则 ALTER USER 'root'@'localhost' IDENTIF ...

  7. Spring Cloud 系列之 Gateway 服务网关(一)

    什么是 Spring Cloud Gateway Spring Cloud Gateway 作为 Spring Cloud 生态系统中的网关,目标是替代 Netflix Zuul,其不仅提供统一的路由 ...

  8. c语言中的引用使用

    最近在写一个图像处理的程序时候,遇到一些传参的问题,最后发现引用的效率高一些,在此提醒各位道友,多多关注引用的应用及使用. 1.在引用的使用中,单纯给某个变量取个别名是毫无意义的,不要为了耍酷而乱用, ...

  9. Hadoop权威指南(中文版-带目录索引)pdf电子书

      Hadoop权威指南(中文版-带目录索引)pdf电子书下载地址:百度网盘点击下载:链接:https://pan.baidu.com/s/1E-8eLaaqTCkKESNPDqq0jw 提取码:g6 ...

  10. stand up meeting 11/25/2015 暨sprint2总结

    今天在课堂上进行了小组项目的阶段性总结,这两天小组内也是频繁的开会,具体细节我们已经反复核查,具体不表~ sprint2个人工作总结: 冯晓云:完成了必应词典在线查词api的调用和网络状况的检测:完成 ...