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. linux 配置 python3 CGI

    文章更新于:2020-03-04 注1:安装 python 参见: python 的安装使用和基本语法 注2:配置 web 环境参见: Windows&linux使用集成环境搭建 web 服务 ...

  2. Scrapy-02-item管道、shell、选择器

    Scrapy-02 item管道: scrapy提供了item对象来对爬取的数据进行保存,它的使用方法和字典类似,不过,相比字典,item多了额外的保护机制,可以避免拼写错误和定义字段错误. 创建的i ...

  3. Docker 常用命令(.NET Core示例)

    Docker安装 CentOS Docker 安装 安装 Docker Desktop for Mac.Docker Desktop for Windows 设置docker仓库镜像加速器 迁移Doc ...

  4. python10

     一.多进程multiprocessing multiprocessing包是Python中的多进程管理包.与threading.Thread类似,它可以利用multiprocessing.Proce ...

  5. 史上最详细mac安装Qt教程

    史上最详细mac安装Qt教程,小白看过来! 这是一篇非常适合Qt入门小白的的安装Qt教程,因为这学期我们小组的一个关于高速救援的项目要用到Qt与web进行交互式展现相关的图像,由于没有MSVC这个插件 ...

  6. matplotlib Bbox类

    Bbox 类是一个可变的(相对于BboxBase)限位框, 继承自BboxBase 2020-04-07 22:54:57  --Edit by yangray 方法: __init__(points ...

  7. C# 基础知识系列- 9 字符串的更多用法(二)

    0. 前言 上一篇文章介绍了字符串自身的一些方法,就是对象方法.在字符串体系中,还有一些是string类提供的静态方法.这两部分构成了字符串体系,当然还有一些三方库为字符串提供了扩展方法. 这里简单的 ...

  8. docker安装GD扩展

    apt update #更新软件源 apt install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev #安装各种库 docker-p ...

  9. BAT脚本编写要点_特殊字符

    BAT脚本编写要点(1)_特殊字符 分类: 其他 2011-03-20 00:58 5621人阅读 评论(0) 收藏 举报 脚本cdatecmdtreesystem 1. 点 与echo连用,作用是换 ...

  10. 【python实现卷积神经网络】定义训练和测试过程

    代码来源:https://github.com/eriklindernoren/ML-From-Scratch 卷积神经网络中卷积层Conv2D(带stride.padding)的具体实现:https ...