Codeforces 911E - Stack Sorting
思路:
用栈来模拟,能pop就pop,记下一个需要pop的数为temp,那么如果栈非空,栈顶肯定大于temp,那么加入栈 栈顶值-1 到 temp 的值,否则加入栈 n 到 temp 的值,如果需要加入的数之前已经出现过,答案则不存在。
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define meme(a,b) memset(a,b,sizeof(a)) const int N=2e5+;
bool vis[N];
int a[N];
stack<int>s;
int main(){
ios::sync_with_stdio(false);
cin.tie();
int n,k;
cin>>n>>k;
int temp=;
for(int i=;i<=k;i++){
cin>>a[i];
vis[a[i]]=true;
s.push(a[i]);
while(s.size()&&s.top()==temp){
s.pop();
temp++;
}
}
while(s.size()&&s.top()>temp||n+>temp){
int t;
if(s.size())t=s.top();
else t=n+;
for(int i=t-;i>=temp;i--){
if(vis[i]){
cout<<-<<endl;
return ;
}
else s.push(i),a[++k]=i,vis[i]=true;
}
while(s.size()&&s.top()==temp){
s.pop();
temp++;
}
}
if(s.size())cout<<-<<endl;
else for(int i=;i<=n;i++)cout<<a[i]<<' ';
cout<<endl;
return ;
}
Codeforces 911E - Stack Sorting的更多相关文章
- CF911E Stack Sorting
洛谷题目链接:CF911E Stack Sorting Codeforces题目链接:Stack Sorting 题意翻译 给你一排列的一部分,让你补全整个排列使其字典序最大并且经过一个栈调整顺序之后 ...
- Stack Sorting CodeForces - 911E (思维+单调栈思想)
Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty) ...
- Codeforces 606-C:Sorting Railway Cars(LIS)
C. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- codeforces 876 D. Sorting the Coins
http://codeforces.com/contest/876/problem/D D. Sorting the Coins time limit per test 1 second memory ...
- Codeforces Round #335 Sorting Railway Cars 动态规划
题目链接: http://www.codeforces.com/contest/606/problem/C 一道dp问题,我们可以考虑什么情况下移动,才能移动最少.很明显,除去需要移动的车,剩下的车, ...
- Codeforces 830B - Cards Sorting 树状数组
B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- codeforces 876 D. Sorting the Coins(线段树(不用线段树写也行线段树写比较装逼))
题目链接:http://codeforces.com/contest/876/problem/D 题解:一道简单的类似模拟的题目.其实就是看右边连出来有多少连续不需要换的假设位置为pos只要找pos- ...
- codeforces 484C Strange Sorting Codeforces Round #276 (Div. 1) C
思路:首先 他是对1到k 元素做一次变换,然后对2到k+1个元素做一次变化....依次做完. 如果我们对1到k个元素做完一次变换后,把整个数组循环左移一个.那么第二次还是对1 到 k个元素做和第一次一 ...
- Codeforces 1240B. Sequence Sorting
传送门 分析题目发现如果把某个数 $x$ 往左移,那么之后所有小于 $x$ 的数也都要往左移 如果把 $x$ 往右移,那么之后所有大于 $x$ 的数也都要往右移 考虑我们首先一定有一个操作 $n$ 次 ...
随机推荐
- VUE路由去除#问题
最近自己在写一个vue的小型管理系统,在浏览器中看到的路由都是带有#的,很是不好看.为了解决此问题,大家一般都会想到:mode: 'history'.可是在开发阶段没有问题,但是一旦build打包后, ...
- 登陆跳板机每天只输入一次token的方法——ssh clone session
自从跳板机升级后,无所不在的token让小PE很是恼火,于是有了这篇文章@_@ Linux or Mac篇 在Fedora或者Mac下很简单,修改~/.ssh/config文件,没有的话,就新建一个( ...
- 利用<object>和<embed>实现视频播放
直接使用<object>或<embed>都可以实现视频播放,那么两者的区别是什么? 1.是为了兼容不同浏览器,IE只支持对Object的解析:火狐,谷歌,Safari只支持对E ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON HistoToThresh2
zw版[转发·台湾nvp系列Delphi例程]HALCON HistoToThresh2 procedure TForm1.Button1Click(Sender: TObject);var imag ...
- codeforces D - Arthur and Walls
这题说的是给了一个矩阵,必须让.连接起来的图形变成矩形,2000*2000的矩形,那么我们就可以知道了,只要是存在一个有点的区域应该尽量将他削为矩形,那么将这个图形进行缩放,最后我们知道只要存在一个2 ...
- FAFU 1395
动态规划:...翻牌FAFU 1395 动态规划
- Linux基础命令---lsusb
lsusb 显示本机的usb设备列表,可以显示出usb的详细信息,包括设备的读取速度和描述符.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE ...
- CSS3实现8种Loading效果【二】
CSS3实现8种Loading效果[二] 今晚吃完饭回宿舍又捣鼓了另外几种Loading效果,老规矩,直接“上菜“…… 注:gif图片动画有些卡顿,非实际效果! 第一种效果: 代码如下: < ...
- 如何向GLSL中传入多个纹理
http://blog.csdn.net/huawenguang/article/details/41245871 如何向GLSL中传入多个纹理 这几天在研究如何实现用GLSL对多个纹理进行融合处理, ...
- python-kafka之理论篇
kafka系列文章之python-api的使用. 在使用kafka-python时候需要注意,一定要版本兼容,否则在使用生产者会报 无法更新元数据的错误. 在本片测试中java版本为如下,kafka版 ...