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");elsesolve();}
}

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) A Dead Pixel

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

  2. Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))

    Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) 题号 题目 知识点 A Simply Strange Sor ...

  3. Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) A-F全题解

    Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) 文章目录 A. Simply Strange Sort B. ...

  4. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)

    今天看不下去数电vp一场div2,搞A搞了很长时间,导致后面没有时间写,不过今天补题的时候全是独立补出来的没有看题解 vp3题,补3题 A - Kids Seating 最开始想的是与质数有关,乱七八 ...

  5. Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)切题报告(A-B题)

    这是我第二次参加CF比赛,也是第一次写博客,写得不好,望各位大佬海涵. A. Single Wildcard Pattern Matching 原题链接 这道题,这是难到让人无法直视,太水了. 题目大 ...

  6. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

    A. Doggo Recoloring ps:注意 n == 1 B. Weakened Common Divisor 题解:WCD出现中的数必然是 < a, b >中某个数的公约数.而 ...

  7. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3)

    点击打开A题链接 #include<bits/stdc++.h> using namespace std; const int MAX = 105; int n,s;int h[MAX], ...

  8. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)B. Primal Sport

    Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try ...

  9. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)C. Voltage Keepsake

    题目链接:C. Voltage Keepsake 题解:二分时间,然后判断看需要充电的时间总和是否在允许的范围内 #include<bits/stdc++.h> #define pb pu ...

最新文章

  1. ASP.NET中绑定枚举类型
  2. [python] 之all()和any()内置函数
  3. 2020年一季度中小微企业收入平均下降69.5%
  4. [运维]---linux机器一般监控用到的概念记录
  5. freemarker -基本概念
  6. hibernate笔记--缓存机制之 二级缓存(sessionFactory)和查询缓存
  7. Mac 安装mysql8
  8. 如何使用Ubuntu安装QQ音乐Linux版本
  9. python中使用什么表示代码块、不需要使用大括号_PYTHON基础语法
  10. MIT 18.01 单变量微积分总结
  11. php 关于模板的原理和解析,PHP-关于模板的原理和解析_PHP教程
  12. 计算机网络发展的第四阶段特点,计算机网络的发展可分为哪几个阶段?每个阶段各有什么特点?...
  13. android+考研助手,安卓考研助手问题总结及改进规划
  14. 迅雷太难用了,可以换其他的下载软件
  15. Parrot OS 4.6渗透测试系统安装与基础环境搭建
  16. JavaScript_原型链继承
  17. html最多显示两行,css 实现两行或多行文本溢出显示省略号(...)
  18. 专利之争:诺基亚与苹果互指对方侵权(每日关注2009.12.31)
  19. CSR867x — uart串口调试和AT指令
  20. 福布斯发布全球富豪榜 巴菲特问鼎首富

热门文章

  1. gdi 编程c语言pdf,二、Windows编程GDI—TextOut细节
  2. iOS中XML解析汇总
  3. java连接mysql 5.7数据库_javaJDBC连接mysql(5.7)数据库,一看就懂的详细例子
  4. cpucores_CPUCores怎么用 CPUCores使用方法指南_3DM单机
  5. 阐述:SIP协议是什么
  6. eclipse导出Maven依赖的Jar
  7. 设计模式系列之单例模式(java)
  8. plsql查询中补入空行--做报表分页挺有用
  9. 华为辞职门事件——再谈工作问题
  10. 四个你看后可能会影响你一生的故事