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 ...
随机推荐
- Executor等系列概念介绍
这里对几个常见的的名词进行介绍 Executor 这是个接口,只声明了一个方法—— public interface Executor { void execute(Runnable command) ...
- 按位&按位|按位~的详解
十进制转二进制: 例:十进制(5)---->二进制(00000101) 将整数除二取余,继续用除二的结果除二取余,最后将结果从下往上连接起来,不足八位,前面填0 二进制转十进制 例:二进制(00 ...
- 一起来学Spring Cloud | 第三章:服务消费者 (负载均衡Ribbon)
一.负载均衡的简介: 负载均衡是高可用架构的一个关键组件,主要用来提高性能和可用性,通过负载均衡将流量分发到多个服务器,多服务器能够消除单个服务器的故障,减轻单个服务器的访问压力. 1.服务端负载均衡 ...
- 7、斐波那契数列、跳台阶、变态跳台阶、矩形覆盖------------>剑指offer系列
题目:斐波那契数列 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0). f(n) = f(n-1) + f(n-2) 基本思路 这道题在剑指offe ...
- 对话框窗口最大化盖住任务栏问题!OnGetMinMaxInfo,WM_GETMINMAXINFO
http://hi.baidu.com/csacer/item/37cd6ac2dec18d360831c6a7 在写程序时,如果包含了标题栏,但是没有包含最大化按钮或者最小话按钮,那么人工用Show ...
- 国内的Jquery CDN免费服务
Jquery是个非常流行的JS前端框架,在很多网站都能看到它的身影.很多网站都喜欢采用一些Jquery CDN加速服务,这样网站加载jquery会更快.之前火端网络的一些网站都是使用Google的jq ...
- 《Python基础教程》 读书笔记 第九章 魔法方法、属性和迭代器(上)
构造方法 在Python中创建一个构造方法很容易.只要把init方法的名字从简单的init修改为魔法版本__init__即可: >>> class FooBar: ... d ...
- freebsd安装snmp
pkg_add http://ip地址/pub/FreeBSD/ports/packages/Latest/net-snmp.tbzFetching http://ip地址/pub/FreeBSD/p ...
- Hibernate:Disjunction&Conjunction构造复杂的查询条件.
Hibernate:Disjunction&Conjunction构造复杂的查询条件 Disjunction和Conjunction是逻辑或和逻辑与,如下: 用来组合一组逻辑或[or]条件的方 ...
- Thread源码分析-java8
1.Thread特性分析 守护线程Daemon 定性:支持性线程,主要用于程序中后台调度以及支持性工作. 当JVM中不存在Daemon线程时,JVM将会退出. 将一个线程设定为Daemon的方法: 调 ...