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");
else
solve();
}
}
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)D. Recommendations
VK news recommendation system daily selects interesting publications of one of n disjoint categories ...
- 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( ...
- Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine)
A. Dead Pixel(思路) 思路 题意:给我们一个m*n的表格,又给了我们表格中的一个点a,其坐标为(x, y),问在这个表格中选择一个不包括改点a的最大面积的矩形,输出这个最大面积 分析:很 ...
- 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 ...
- 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 >> ...
- Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)【ABCDF】
比赛链接:https://codeforces.com/contest/1443 A. Kids Seating 题意 构造一个大小为 \(n\) 的数组使得任意两个数既不互质也不相互整除,要求所有数 ...
- Codeforces Round #681 (Div. 1, based on VK Cup 2019-2020 - Final) B. Identify the Operations (模拟,双向链表)
题意:给你一组不重复的序列\(a\),每次可以选择一个数删除它左边或右边的一个数,并将选择的数append到数组\(b\)中,现在给你数组\(b\),问有多少种方案数得到\(b\). 题解:我们可以记 ...
- 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\). 题解: ...
- Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) C. The Delivery Dilemma (贪心,结构体排序)
题意:你要买\(n\)份午饭,你可以选择自己去买,或者叫外卖,每份午饭\(i\)自己去买需要消耗时间\(b_i\),叫外卖需要\(a_i\),外卖可以同时送,自己只能买完一份后回家再去买下一份,问最少 ...
随机推荐
- 微信小程序mpvue-动态改变navigationBarTitleText值
通过JS动态 改变navigationBarTitleText的值 能否通过JS动态改变navigationBarTitleText的值? 方法一:可以在onLoad方法中通过wx.setNaviga ...
- Linux基础篇,系统服务(service)的管理
一.服务是什么? 用白话文说,服务就是"常驻在内存中的进程",用来提供一些系统或网络功能. 二.service和daemon的区别与联系 因为服务(service)本质上来说也是程 ...
- hadoop(六)rsync远程同步|xsync集群分发(完全分布式准备三)|8
前置环境准备:centos7克隆ip|机器名|映射关系|别名配置(hadoop完全分布式准备一)scp命令copy文件和配置(hadoop完全分布式准备二) rsync远程同步工具 优点 rsync主 ...
- 【Java】Operator 运算符/操作符
Operator 运算符/操作符 什么是操作符? 一个表示特定的数学或逻辑操作的符号 算术运算符 加 + 减 - 乘 * 除 / 取模 % 前置自运算 ++ a .--b 后置自运算 a++ .b-- ...
- 第十三节:telnetlib、redis、threading模块
telnetlib模块案例: import telnetlib,re class TelnetInfo(): def telnetdo(self, host, port, command): tn = ...
- JuiceSSH:安卓平台免费好用的 SSH 客户端
为了解决上下班路上或者没带电脑时,查看 Linux 服务器日志或者紧急运维的需求,最终找到了 JuiceSSH 这款软件,强烈推荐给大家. 简介 JuiceSSH 是一个为 Android 打造的全功 ...
- 使用snapjs实现svg路径描边动画
一,snap.svg插件在近几天,突然接到一个需求,内容是要在网页上写一个路径的动画,还需要可以随意控制动画的速度,开始于结束,本来是一个图片可以解决的问题,结果就这样变难了呀,在网上查一会之后,突然 ...
- 3d模型一般怎么导入到到Threejs中使用
这是我之前做的一个demo,导入的3d模型文件是obj格式的,需要使用OBJLoader和MTLLoader, mtl文件用于描述多边形可视面貌的材质如果你可以导出obj.mtl文件的话,那么就可以使 ...
- Python程序设计实验报告四:循环结构程序设计(设计型实验)
安徽工程大学 Python程序设计 实验报告 班级 物流191 姓名 姚彩琴 学号3190505129 成绩 日期 2020.4.8 指导老师 修宇 [实验名称 ...
- linux之cat 操作
1.查看或创建 cat 1.txt #如果目录有这个文件则会打开查看,没有则会创建 2.压缩空白 cat 1.txt 我是第一行 我是第二 行 cat -bs 1.txt # 变成 cat 1.txt ...