The North American Invitational Programming Contest 2018 D. Missing Gnomes
A family of nn gnomes likes to line up for a group picture. Each gnome can be uniquely identified by a number 1..n1..n written on their hat.
Suppose there are 55 gnomes. The gnomes could line up like so: 1, 3, 4, 2, 51,3,4,2,5.
Now, an evil magician will remove some of the gnomes from the lineup and wipe your memory of the order of the gnomes. The result is a subsequence, perhaps like so: 1, 4, 21,4,2.
He then tells you that if you ordered all permutations of 1..n1..n in lexicographical order, the original sequence of gnomes is the first such permutation which contains the remaining subsequence. Your task is to find the original sequence of gnomes.
Input Format
Each input will consist of a single test case.
Note that your program may be run multiple times on different inputs.
Each test case will begin with a line with two integers nn and then m (1 \le m \le n \le 10^5)m(1≤m≤n≤105), where nn is the number of gnomes originally, and mm is the number of gnomes remaining after the evil magician pulls his trick. Each of the next mm lines will contain a single integer g (1 \le g \le n)g(1≤g≤n). These are the remaining gnomes, in order. The values of gg are guaranteed to be unique.
Output Format
Output nn lines, each containing a single integer, representing the first permutation of gnomes that could contain the remaining gnomes in order.
样例输入1
5 3
1
4
2
样例输出1
1
3
4
2
5
样例输入2
7 4
6
4
2
1
样例输出2
3
5
6
4
2
1
7
题目来源
The North American Invitational Programming Contest 2018
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
using namespace std;
#define ll long long
#define N 100009
#define gep(i,a,b) for(int i=a;i<=b;i++)
#define gepp(i,a,b) for(int i=a;i>=b;i--)
#define gep1(i,a,b) for(ll i=a;i<=b;i++)
#define gepp1(i,a,b) for(ll i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof(a))
int n,m;
bool vis[N];
int a[N];
int main()
{
scanf("%d%d",&n,&m);
int pos=;
int x;
gep(i,,m){
scanf("%d",&a[i]);
vis[a[i]]=;
}
int j;
gep(i,,m){
for(j=pos;j<=a[i];j++){
if(!vis[j]){
vis[j]=;
printf("%d\n",j);
}
}
pos=j;
printf("%d\n",a[i]);
}
gep(i,,n){
if(!vis[i]){
printf("%d\n",i);
}
}
return ;
}
The North American Invitational Programming Contest 2018 D. Missing Gnomes的更多相关文章
- The North American Invitational Programming Contest 2018 H. Recovery
Consider an n \times mn×m matrix of ones and zeros. For example, this 4 \times 44×4: \displaystyle \ ...
- The North American Invitational Programming Contest 2018 E. Prefix Free Code
Consider nn initial strings of lower case letters, where no initial string is a prefix of any other ...
- North American Invitational Programming Contest 2018
A. Cut it Out! 枚举第一刀,那么之后每切一刀都会将原问题划分成两个子问题. 考虑DP,设$f[l][r]$表示$l$点顺时针一直到$r$点还未切割的最小代价,预处理出每条边的代价转移即可 ...
- The North American Invitational Programming Contest 2017 题目
NAIPC 2017 Yin and Yang Stones 75.39% 1000ms 262144K A mysterious circular arrangement of black st ...
- North American Invitational Programming Contest (NAIPC) 2017
(待补) A. Pieces of Parentheses 将括号处理完成后排序,方式参加下面的博客.然后做一遍背包即可. 2018 Multi-University Training Contest ...
- North American Invitational Programming Contest (NAIPC) 2016
(待补) A. Fancy Antiques 爆搜. B. Alternative Bracket Notation C. Greetings! D. Programming Team 0/1分数规划 ...
- AtCoder SoundHound Inc. Programming Contest 2018 E + Graph (soundhound2018_summer_qual_e)
原文链接https://www.cnblogs.com/zhouzhendong/p/AtCoder-SoundHound-Inc-Programming-Contest-2018-E.html 题目 ...
- ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018
ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syr ...
- German Collegiate Programming Contest 2018 B. Battle Royale
Battle Royale games are the current trend in video games and Gamers Concealed Punching Circles (GCPC ...
随机推荐
- AmazeUI 保存浏览器数据 永久性
//保存永久缓存数据function SaveAmuiStore(ItemName, ItemData){ if (window.localStorage) { var store = $.AMUI. ...
- VS中以插件开发的思想开发Winform应用
简单定义: 插件(也称构件)式开发:主要内容就是一个宿主程序加上后期开发的若干插件程序构成整个系统! 宿主程序提供接口注册,插件注册实现接口,从而使不同的插件提供新的功能: 举例: 以下是用VS中的W ...
- hihocoder1829 Tomb Raider
思路: 暴力枚举. 实现: #include <iostream> #include <set> #include <vector> using namespace ...
- 【详解】JS中的作用域、闭包和回收机制
在讲解主要内容之前,我们先来看看JS的解析顺序,我们惯性地觉得JS是从上往下执行的,所以我们要用一个变量来首先声明它,来看下面这段代码: alert(a); var a = 1; 大家觉得这段代码有什 ...
- WebService学习之旅(四)Apache Axis2的安装
一.Axis2简介 Axis2是目前使用较多的WebService引擎,它是Axis1.x的升级版本,不仅支持SOAP1.1和SOAP1.2,而且也提供了对REST风格WebService的支持. A ...
- 浅谈C++ 内存泄漏及其检测工具
浅谈C++ 内存泄漏及其检测工具 http://wenku.baidu.com/link?url=1DGkOOvd_ITZyB8IHAwfhCOx2tfO6id8UfuyQkAMHZU6sasaAXz ...
- PHP小数处理常用函数
1.php保留两位小数并且四舍五入 $num = 123213.666666; echo sprintf("%.2f", $num); // 123213.67echo round ...
- LR中排序脚本
/* * LoadRunner Java script. (Build: 670) * * Script Description: * */ import lrapi.lr; public class ...
- red5 重新分配 ip
root@hett-OptiPlex-7040:~# ll /usr/local/src/red5/conf/total 144drwxr-xr-x 2 root root 4096 1月 9 ...
- 程序windows上可以上传附件,部署到 linux服务器后出现 “上传目录 不可写” 怎么解决?
这样的问题一般都是linux 下文件读写权限引起的,用 shell 命名到上传附件的目录(如 cd /data/www/project/upload/),然后执行 shell 文件权限设置: 例如 ...