codeforces 767A Snacktower(模拟)
A. Snacktower
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.

However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
The first line contains single integer n (1 ≤ n ≤ 100 000) — the total number of snacks.
The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
3
3 1 2
3 2 1
5
4 5 1 2 3
5 4
3 2 1
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
题目链接:http://codeforces.com/contest/767/problem/A
题意:给出一列数,让你把这个数按照从大到小输出,当然数字必须要连续,并且比他小的数在序列中位置必须要在他前面,比如,给你5个数,那么,你第一个数当然要找5,然后看5所在位置前面有没有4接着往下,如果不等就输出空行。
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std;
const int N=;
int a[N]={};
int main()
{
int n;
scanf("%d",&n);
int m=n;
for(int i=;i<n;i++)
{
int p;
cin>>p;
a[p]=;////对各个位置数进行标记,实际上在进行着排序
while(a[m]==)
{
printf("%d ",m);
m--;
}
printf("\n");
}
return ;
}
codeforces 767A Snacktower(模拟)的更多相关文章
- CodeForces - 767A Snacktower
题目大意 一个数可以被输出当且仅当所有比它大的数都已经输出.输入一个1~n的排列,求每次输出的输出序列. 题解 直接用堆模拟 #include <queue> #include <c ...
- Codeforces Round #398 (Div. 2) A. Snacktower 模拟
A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old lege ...
- 【codeforces 767A】Snacktower
[题目链接]:http://codeforces.com/contest/767/problem/A [题意] 每天掉一个盘子下来;盘子有大小从1..n依次增大n个盘子; 然后让你叠盘子; 最底层为n ...
- Codeforces 389B(十字模拟)
Fox and Cross Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submi ...
- codeforces 591B Rebranding (模拟)
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...
- Codeforces 626B Cards(模拟+规律)
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- Codeforces 631C. Report 模拟
C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- Codeforces 679B. Barnicle 模拟
B. Barnicle time limit per test: 1 second memory limit per test :256 megabytes input: standard input ...
- CodeForces 382C【模拟】
活生生打成了大模拟... #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsig ...
随机推荐
- loadrunner设置分压机 压力测试
压力机设置分压机使用场景: 当本地主机内存较小,运行速度较慢,压力较大等多种需求场景下,可以使用分压机. 一.将另一台机器设置为压力机 1,开始菜单找到HP LoadRunner-->Advan ...
- iOS 内存泄漏排查以及处理
使用Xcode7的Instruments检测解决iOS内存泄露 文/笨笨的糯糯(简书作者)原文链接:http://www.jianshu.com/p/0837331875f0作为一名iOS开发攻城 ...
- office------------word邮件合并(word2016版)
虽然本人是学计算机的,但是office技能很一般,最近工作中用到了邮件合并这一功能,记录下来与大家分享. 我用到的邮件合并就是word中定好模板,从excel中批量导入数据,现实生活中,在录取通知书打 ...
- SSL/TLS通信
本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/31 复习基本概念 对称密码:加密和解密使用同一密匙. 公钥密码: ...
- Who's in the Middle
FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median' ...
- Linux第九讲随笔 -进程管理 、ps aux 、
Linux第九讲1,进程管理 Linux在执行每一个程序时,就会在内存中为这个程序建立一个进程,以便让内核可以管理这个运行中的进程,进程是系统分配各种资源,进程调度的基本单位. 怎么查看进程 一.ps ...
- Mysql5.7.20 On Windows安装指导
安装环境 Windows版本:Windows10 64bit MySQL版本: MySQL5.7.20 配置过程 1.下载MySQL Community Server (下载链接) 根据自己操作系统需 ...
- for 在项目实战中用的比较多
for循环编程语言中的语句之一,用于循环执行.for循环是开界的,它的一般形式为: for(; <条件表达式>; ) 语句: 初始化通常是一个赋值语句, 它用来给循环控制变量赋初值: 条件 ...
- IDEA 环境设置
IDEA环境设置 任何事物都有两面性,如何用好才是关键.IDEA为我们提供了丰富的功能,但不代表默认的配置就适合于你.我们应当根据自己的条件.需求合理的配置,从而驾驭好这匹悍马.让它成为我们编程的利器 ...
- 浅谈OGNL表达式
OGNL(Object-Graph Navigation Language):对象视图导航语言 ${user.addr.name}这样的写法就叫对象视图导航 OGNL不仅可以视图导航,支持EL表达式更 ...