Restoring Permutation CodeForces - 1315C(思维)
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
Input
5
1
1
2
4 1
3
4 1 3
4
2 3 4 5
5
1 5 7 2 8
Output
1 2
-1
4 5 1 2 3 6
-1
1 3 5 6 7 9 2 4 8 10
思路:这是我做过最水的C题。二分寻找符合条件的最小值就可以了。如果找不到,那么就不对。
代码如下:
#include<bits/stdc++.h>
#define ll long long
using namespace std;const int maxx=5e2+100;
vector<int> a,b,c;
int vis[maxx];
int n;inline void init()
{a.clear();b.clear();c.clear();memset(vis,0,sizeof(vis));
}
int main()
{int t,x,y;scanf("%d",&t);while(t--){scanf("%d",&n);init();for(int i=1;i<=n;i++) scanf("%d",&x),vis[x]=1,a.push_back(x);for(int i=1;i<=2*n;i++) if(!vis[i]) b.push_back(i);int flag=1;for(int i=0;i<n;i++){x=a[i];y=lower_bound(b.begin(),b.end(),x)-b.begin();if(y==b.size()){flag=0;break;}c.push_back(x);c.push_back(b[y]);b.erase(b.begin()+y);}if(flag==0) cout<<"-1"<<endl;else for(int i=0;i<2*n;i++) cout<<c[i]<<" ";cout<<endl;}return 0;
}
努力加油a啊,(o)/~
Restoring Permutation CodeForces - 1315C(思维)相关推荐
- codeforces - 1315C - 思维题
原题链接:https://codeforces.com/problemset/problem/1315/C 翻译: 这是一个猜谜游戏,你需要猜中一个序列,谜题是一个序列,我们设为b,长度为n.你需要根 ...
- Levko and Permutation CodeForces - 361B 思维 数论
题意 对一个长度,最大值为n的排列 构造出其恰好有k个GCD(i,a[i])>1 的排列 n<=1e5; 分析 由于每个大于1的数与自己的gcd必然>1 所以构造大于1的gcd可以用 ...
- Restoring the Permutation CodeForces - 1506E
题目链接:E. Restoring the Permutation 题解:按字典序最小的简单一点,字典序大的较为复杂,找出字典序最大的可以通过栈,如果当前的a[i]值和a[i-1]值不相等,说明b[i ...
- CodeForces 798D 思维,贪心
CodeForces 798D 题意:长度为 n的两个数组 a[]和 b[],要找出 k ( k<=n/2+1 )个下标,使得在两个数组中这 k个数的和乘上 2 要大于所有数的和. tags: ...
- C. Restoring Permutation
链接:https://codeforces.ml/contest/1315/problem/C You are given a sequence b1,b2,-,bnb1,b2,-,bn. Find ...
- Minimize the Permutation CodeForces - 1256(贪心)
题意: q次询问,每次询问给你长度为n的排列,然后你每次可以选择一个位置i和i+1的数字进行交换.但是每个位置只能交换一次,问你反转若干次后,这个排列最小是多少? 题目: You are given ...
- B. Restoring Painting CodeForces - 675B
原题链接 位于CodeForceshttps://codeforces.com/problemset/problem/675/B 翻译 小 V 在玩填数游戏,游戏在 3×3 的正方形中进行. 9 个格 ...
- Balanced Substring CodeForces - 873B (思维+前缀和)
Balanced Substring CodeForces - 873B You are given a string s consisting only of characters 0 and 1. ...
- Blue-Red Permutation 贪心,思维
题意 : 给一序列以及序列对应每个位置的颜色,R颜色对应可以增加若干,B反之,问是否能将序列变化为1-n所有数有且仅有1个 思路 : 每个数可以得到一个变化范围区间,那么得到了n个区间,区间只存左右端 ...
最新文章
- 使用leangoo做多团队敏捷开发项目管理
- tf.clip_by_value() 用法
- Handler消息处理机制
- HCNA配置telnet远程管理
- 安装英文版xp时选择安装亚洲中文语言包
- 万用表测电容方法-电子技术方案
- Mybatis中 if 语句使用空格问题
- Python 爬楼梯问题--有n阶台阶,上楼可以一步上1阶,2阶,3阶,计算共有多少种不同的走法?
- 求最大公约数,最小公倍数
- 学ui需要了解html,学UI设计需要掌握文案知识吗
- 北京开始整治互联网加班了!附 955 不加班公司名单(2022版)
- SVN服务器迁移方法(Windows环境)
- 字符串字符数组的赋值
- Vue-高德地图-立体多边形绘制
- 2019浙江计算机二级考试考纲,计算机二级考试大纲(2019全国计算机二级考试大纲)...
- 华为或成韩国电信最大5G设备供应商!
- sas和python哪个更容易发胖_BEC商务英语_沙拉vs.巨无霸:哪个更容易发胖?_沪江英语...
- Android 收集的开源项目和文章集合
- 《go语言核心36讲》栏目心得
- 基于SSM汽车买卖保养维护网站
热门文章
- IOS开发基础之单例模式
- db2 mysql sql server_下文给大家介绍mysql数据库介绍,具体详情如下所示:MySQL数据库:Oracle、DB2、SQL Server、MySQL、access、mang...
- cmd,powershell,的字体颜色永久改变,;以及两者不同打开方式和其各自的区别。
- linux p2p视频播放器,avplayer: 一个基于FFmpeg、libtorrent的P2P播放器实现.
- 《深入浅出数据分析》第十三章
- Android开发之百度地图距离判断(判断定位位置是否在圆的范围内)
- mysql数据库没有密码_MySQL用户数据库没有密码列-在OSX上安装MySQL
- Django的ModelForm
- 使用SVN提示“工作副本已经锁定”的解决办法
- Android ORM 框架:GreenDao 数据库升级