Codeforces Round #398 (Div. 2) A. Snacktower 模拟
A. Snacktower
题目连接:
http://codeforces.com/contest/767/problem/A
Description
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.
Input
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.
Output
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.
Sample Input
3
3 1 2
Sample Output
3
2 1
Hint
题意
有个奇怪的人,他会每天吃东西,他会先吃大的。比如第一天就会吃n,第二天吃n-1,第三天吃n-2。
如果这一天不是这个东西的话,他会一直等着这个东西出现,然后一口气吃掉。
题解:
大概就是模拟一下题意吧。
我翻译的题意实际上比较乱啦,感觉只有自己看得懂……
嘛,不懂就看我代码吧。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int vis[maxn],a[maxn],b[maxn],flag;
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
flag = n;
for(int i=1;i<=n;i++){
b[a[i]]=1;
while(b[flag]){
printf("%d ",flag);
flag--;
}
printf("\n");
}
}
Codeforces Round #398 (Div. 2) A. Snacktower 模拟的更多相关文章
- 【暴力】Codeforces Round #398 (Div. 2) A. Snacktower
题意不复述. 用个bool数组记录一下,如果某一天,当前剩下的最大的出现了的话,就输出一段. #include<cstdio> using namespace std; int n; bo ...
- Codeforces Round #398 (Div. 2)
Codeforces Round #398 (Div. 2) A.Snacktower 模拟 我和官方题解的命名神相似...$has$ #include <iostream> #inclu ...
- Codeforces Round #398 (Div. 2) A B C D 模拟 细节 dfs 贪心
A. Snacktower time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)
A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces Round #398 (div.2)简要题解
这场cf时间特别好,周六下午,于是就打了打(谁叫我永远1800上不去div1) 比以前div2的题目更均衡了,没有太简单和太难的...好像B题难度高了很多,然后卡了很多人. 然后我最后做了四题,E题感 ...
- Codeforces Round #543 (Div. 2) D 双指针 + 模拟
https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...
- Codeforces Round #398 (Div. 2) A-E
分数史上新低 开场5分钟过了A题,想着这次赌一把手速,先去切C吧 看完C题觉得这应该是道水题,码了十分钟提交,WA 想着这明明是道水题,估计少考虑了情况,添了几行再交,WA 不可能啊,这题都A不掉,和 ...
- Codeforces Round #237 (Div. 2) B题模拟题
链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...
随机推荐
- 何凯文每日一句打卡||DAY9
- Zephir入门教程一
一.如何安装 zephir-安装和初体验:http://blog.csdn.net/u011142688/article/details/51619811 二.如何使用 需要切到工作目录下,也就是co ...
- GraphChi/graphchi-java程序配置
1.导入graphchi-java maven项目时报错: Plugin execution not covered by lifecycle configuration: org.scala-too ...
- html5 canvas显示文字(写上5个字,纪念我那刚刚逝去的爱情)
<script type="text/javascript"> window.addEventListener('load',eventWindowLoaded,fal ...
- matrix 矩阵(多维DP)
题面 \(solution:\) 这一题其实就是一个非常明显的三维背包问题(但博主太弱了就10分QAQ) \(F[i][j][k]:\)表示走到\((i,j)\)这个位置并且背包容量为 \(k\) 时 ...
- Android的layout_weight和weightSum
先看一下weightSum属性的功能描述:定义weight总和的最大值.如果未指定该值,以所有子视图的layout_weight属性的累加值作为总和的最大值.把weightSum的定义搁在这里,先去看 ...
- mybatis查询缓存——(十三)
1. mybatis缓存介绍 如下图,是mybatis一级缓存和二级缓存的区别图解: mybatis提供查询缓存,用于减轻数据压力,提高数据库性能. mybaits提供一级缓存,和二级缓存.
- mongo批量操作存在更新否则插入
def save_data(ok_ps): ns = [] for ok in ok_ps: ok['last_use_time'] = 0 ok['protocol'] = 0 # 协议类型 0:h ...
- SQL008存储过程总结
1.如何调用存储过程 DECLARE @Id INT --输入参数 DECLARE @OutPutID INT --输出参数 EXEC [dbo].Order_SellPR @Id,@OutPutID ...
- poj2447
题意:两个素数P,Q.N=P*Q; T=(P-1)*(Q-1); (E*D)mod T = 1; (0<=D<T).E与T互质,公钥是{E,N},私钥是{D,N}.原始信息M的加密过程为C ...