Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) C. Restoring
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相关推荐
- 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 ...
- 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 ...
- 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. ...
- Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)
今天看不下去数电vp一场div2,搞A搞了很长时间,导致后面没有时间写,不过今天补题的时候全是独立补出来的没有看题解 vp3题,补3题 A - Kids Seating 最开始想的是与质数有关,乱七八 ...
- Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)切题报告(A-B题)
这是我第二次参加CF比赛,也是第一次写博客,写得不好,望各位大佬海涵. A. Single Wildcard Pattern Matching 原题链接 这道题,这是难到让人无法直视,太水了. 题目大 ...
- 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 >中某个数的公约数.而 ...
- 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], ...
- 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 ...
- 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 ...
最新文章
- ASP.NET中绑定枚举类型
- [python] 之all()和any()内置函数
- 2020年一季度中小微企业收入平均下降69.5%
- [运维]---linux机器一般监控用到的概念记录
- freemarker -基本概念
- hibernate笔记--缓存机制之 二级缓存(sessionFactory)和查询缓存
- Mac 安装mysql8
- 如何使用Ubuntu安装QQ音乐Linux版本
- python中使用什么表示代码块、不需要使用大括号_PYTHON基础语法
- MIT 18.01 单变量微积分总结
- php 关于模板的原理和解析,PHP-关于模板的原理和解析_PHP教程
- 计算机网络发展的第四阶段特点,计算机网络的发展可分为哪几个阶段?每个阶段各有什么特点?...
- android+考研助手,安卓考研助手问题总结及改进规划
- 迅雷太难用了,可以换其他的下载软件
- Parrot OS 4.6渗透测试系统安装与基础环境搭建
- JavaScript_原型链继承
- html最多显示两行,css 实现两行或多行文本溢出显示省略号(...)
- 专利之争:诺基亚与苹果互指对方侵权(每日关注2009.12.31)
- CSR867x — uart串口调试和AT指令
- 福布斯发布全球富豪榜 巴菲特问鼎首富
热门文章
- gdi 编程c语言pdf,二、Windows编程GDI—TextOut细节
- iOS中XML解析汇总
- java连接mysql 5.7数据库_javaJDBC连接mysql(5.7)数据库,一看就懂的详细例子
- cpucores_CPUCores怎么用 CPUCores使用方法指南_3DM单机
- 阐述:SIP协议是什么
- eclipse导出Maven依赖的Jar
- 设计模式系列之单例模式(java)
- plsql查询中补入空行--做报表分页挺有用
- 华为辞职门事件——再谈工作问题
- 四个你看后可能会影响你一生的故事