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. DVWA系列精品教程:2、命令注入

    文章更新于:2020-04-11 注:如何搭建环境参见:搭建DVWA Web渗透测试靶场 DVWA之命令注入漏洞 一.介绍 1.1.官方说明 1.2.总结 二.命令注入实践 2.1.安全级别:LOW ...

  2. WIFI:802.11无线LAN

    IEEE 802.11 无线LAN(也称WiFi) IEEE是什么 电气和电子工程师协会(IEEE,全称是Institute of Electrical and Electronics Enginee ...

  3. wireshark抓包实战(四),数据包的操作

    1.标记数据包 当我们找到一个数据包感觉它很重要时,想要让它更明显怎么办呢?让它高亮即可! 具体操作: 选中某个条目,右键mark即可 2.为数据包添加注释 选中包以后,右键"分组注释&qu ...

  4. css--->圆角设置

    1.为元素添加四个相同的圆角: 语法结构:border-radius:r: r为圆角的半径大小 eg:如下样式,给元素添加四个圆角为10px   代码如下: <!DOCTYPE html> ...

  5. VM卸载不完全,重装的一个下午

    玩软件就是随时面临着重新来过的危险.今天一不小心就把VM给高爆了,爆的很高的那种. 卸载不完全的VM如何在不重装系统的情况下安装. 首先第一步,肯定是通过控制面板去卸载VM,但是....但是...我靠 ...

  6. IntelliJ IDEA 在方法大括号中{}点击回车多出一个},如何取消

    在 File - settings - Editor - General- Smart Keys - Enter 去掉 Insert pair '}' 的对勾就可以了

  7. 钩子函数 Function类

    Function 为 com.google.common.base包下接口类: public interface Function<F, T> { @Nullable T apply(@N ...

  8. iOS线程数量监控工具

    简单却强大的线程监控工具 KKThreadMonitor :当线程过多或瞬间创建大量子线程(线程爆炸),控制台就打印出所有的线程堆栈.便于分析造成子线程过多或线程爆炸的原因. /******* 线程爆 ...

  9. vue的组件缓存(返回页面不刷新)

    每次使用返回是页面总是会刷新 导致了一些体验上的不愉快 现在 发现vue中的一个很方便的方法还可以用来优化性能就是: keep-alive缓存组件 <router-view v-if=" ...

  10. 高级工程师-Java注解

    高级工程师-Java注解 前言 代码,就是我们身为程序员的名片. 简洁,优雅,统一,是我们的追求. 优秀的代码,会给浏览者一种艺术的美感.如DL大神的JUC包,感兴趣的小伙伴,可以研究一下. 那么日常 ...