C. Restoring Permutation
链接:https://codeforces.ml/contest/1315/problem/C
You are given a sequence b1,b2,…,bnb1,b2,…,bn. Find the lexicographically minimal permutation a1,a2,…,a2na1,a2,…,a2n such that bi=min(a2i−1,a2i)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 tt (1≤t≤1001≤t≤100).
The first line of each test case consists of one integer nn — the number of elements in the sequence bb (1≤n≤1001≤n≤100).
The second line of each test case consists of nn different integers b1,…,bnb1,…,bn — elements of the sequence bb (1≤bi≤2n1≤bi≤2n).
It is guaranteed that the sum of nn by all test cases doesn't exceed 100100.
Output
For each test case, if there is no appropriate permutation, print one number −1−1.
Otherwise, print 2n2n integers a1,…,a2na1,…,a2n — required lexicographically minimal permutation of numbers from 11 to 2n2n.
Example
input
Copy
5 1 1 2 4 1 3 4 1 3 4 2 3 4 5 5 1 5 7 2 8
output
Copy
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;
long long n,t,r,q,k,s,max1=0,p;
long long a[10001],b[10001];
map<long long ,long long>m;
int main()
{cin>>t;while(t--){cin>>n;m.clear();for(int i=1;i<=n;i++){cin>>b[i];m[b[i]]=1;}int flag=1;for(int i=1;i<=n;i++){a[i*2-1]=b[i];k=b[i];while(m[k]==1){k++;}if(k<=2*n){a[i*2]=k;m[k]=1;}else{flag=0;break;}}if(flag==0){cout<<-1<<endl;}else{for(int i=1;i<=2*n;i++){cout<<a[i]<<" ";}cout<<endl;}}
}
C. Restoring Permutation相关推荐
- Restoring Permutation CodeForces - 1315C(思维)
You are given a sequence b1,b2,-,bn. Find the lexicographically minimal permutation a1,a2,-,a2n such ...
- 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 inputstandar ...
- E. Restoring the Permutation
E. Restoring the Permutation Example input 4 7 3 3 4 4 7 7 7 4 1 2 3 4 7 3 4 5 5 5 7 7 1 1 output 3 ...
- Restoring the Permutation CodeForces - 1506E
题目链接:E. Restoring the Permutation 题解:按字典序最小的简单一点,字典序大的较为复杂,找出字典序最大的可以通过栈,如果当前的a[i]值和a[i-1]值不相等,说明b[i ...
- Restoring the Permutation
cf题目链接 题意简述:原有一序列p,p中元素为[1,n],通过q[i]=max(p[1],p[2]-,p[i])得到一个新的序列q,现给出q,问满足规则的字典序最大和最小的p序列分别是什么 解法:通 ...
- 【C++】C++11 STL算法(七):排列操作(Permutation operations)、数值操作(Numeric operations)
排列操作(Permutation operations) 一.is_permutation 1.原型: template< class ForwardIt1, class ForwardIt2 ...
- LeetCode 76. Minimum Window Substring / 567. Permutation in String
76. Minimum Window Substring 典型Sliding Window的问题,维护一个区间,当区间满足要求则进行比较选择较小的字串,重新修改start位置. 思路虽然不难,但是如何 ...
- R语言使用lmPerm包应用于线性模型的置换方法(置换检验、permutation tests)、使用lm模型构建简单线性回归模型、使用lmp函数生成置换检验回归分析模型
R语言使用lmPerm包应用于线性模型的置换方法(置换检验.permutation tests).使用lm模型构建简单线性回归模型.使用lmp函数生成置换检验回归分析模型(Permutation te ...
- R语言使用coin包应用于独立性问题的置换检验(permutation tests、响应变量是否独立于组、两个数值变量是独立的吗、两个分类变量是独立的吗)、以及coin包的常用置换检验函数
R语言使用coin包应用于独立性问题的置换检验(permutation tests.响应变量是否独立于组.两个数值变量是独立的吗.两个分类变量是独立的吗).以及coin包的常用置换检验函数 目录
最新文章
- 【图论专题】Floyd算法及其扩展应用
- nginx-URL重写
- 实现抢红包算法?如此简单
- POJ 2553 The Bottom of a Graph
- 【算法导论】第24章迪杰斯特拉算法
- 图解设计模式:状态模式
- MSM8937的sbl1和CDT
- centos ntp日志_centos NTP服务器配置总结
- 中国社会为何多犬儒?
- html群聊插件,团队群聊.html
- 网站流量可视化分析--页面指标分析、访问量分析
- 道一云与畅捷通T+对接集成获取报销信息列表=>凭证创建
- 日语基础复习 Day 4
- 在 阿里云ECS 上安装 CDH6.2 standalong
- PEP8中文翻译(转)
- 十位安卓开发者的 17 年总结
- BZOJ3032 七夕祭 均分纸牌问题的变式 (前缀和+中位数)
- 震惊!手把手教你用Python破解邻家小妹wifi密码
- vuejs集成simditor
- 餐饮供应链管理系统解决方案