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包的常用置换检验函数 目录
最新文章
- python爬网页源码_python爬虫爬取网页的内容和网页源码不同?
- 将VS2005中的.CS文件在网页中显示的方法
- IOC注解注入View
- Starry Night [USACO]
- 自动装配——@Autowired 构造器,参数,方法,属性都是从容器中获取参数组件的值||自定义组件想要使用Spring容器底层的一些组件 ApplicationContext,BeanFactory
- DIV CSS初学者需重视的10个简单问题与技巧
- python的魔法_python魔法方法大全
- 滑动关机代码bat_BAT面试算法进阶--(2) 无重复字符的最长子串(滑动法优化+ASCII码法)...
- 多模块Struts应用程序的几个问题(及部分解决方法)
- 【冰点文库下载器.exe】
- 医学专业学语文数学英语计算机嚒,医学专业到底有哪些一级学科,你知道吗?...
- jszip 解压压缩包_React实现zip压缩解压
- 飞到半路被撞?不是小鸟不专心,而是太阳能太晃眼
- 嗯,好不容易得到面试机会,面试官问的全回答了,但心痒一看状态进了人才库了.....
- Android Provision(开机向导setupwizard程序)
- PYNQ开发板使用-使用DMA进行数据搬移(Simple DMA transfer 模式)
- 网络安全中的NISP-SO安全运维工程师都需要那些工具?
- 千纸鹤(小纸片)全套源码
- 阿里云官方学习课程推荐-Linux运维学习路线 从事云计算运维相关工作必备技能
- Toggle Buttons(四)
热门文章
- MAGCN:基于lncRNA与miRNA相互作用和图卷积网络预测miRNA与疾病的关联(Briefings in Bioinformatics)
- SQL美化dll,C#
- 3.18调查问卷第六题说明
- 如何提升测试质量(技术篇)
- 一块钱一瓶水 两个瓶子可以换一瓶水 给你100块钱 可以喝多少瓶水
- Vue自定义动画/过渡
- 前端工程化实践 - 代码规范 提交规范 构建流程 Monorepo(附 React Native 案例)
- 记:.net 海关179自行加签方法
- JAVA平台的三个版本
- C# NPOI 设置(.xlsx) 【单元格填充】以及【字体颜色】