CodeForces
来源:互联网 发布:榕基软件 编辑:程序博客网 时间:2024/06/15 06:52
题目链接:http://codeforces.com/problemset/problem/767/A点击打开链接
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.
33 1 2
3 2 1
54 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.
隐约印象这是第一次cf比赛的第一题
set+vector乱搞 模拟他的过程
#include<bits/stdc++.h>#define maxn 1000010using namespace std;set<int > s;vector < int > ss,sss;bool cmp(int a,int b){ return a>b;}int main(){ int n=0; scanf("%d",&n); for(int i=0;i<n;i++) { int mid=0; scanf("%d",&mid); ss.push_back(mid); sss.push_back(mid); } sort(sss.begin(),sss.end(),cmp); int temp=0; for(int i=0;i<n;i++) { s.insert(ss[i]); while(s.count(sss[temp])) { printf("%d ",sss[temp]); s.erase(sss[temp]); temp++; } printf("\n"); }}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- JVM的内存区域划分
- 排序算法-选择排序之堆排序
- 51nod 1428 && bzoj 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
- 通过MySQL自动同步刷新Redis
- 合并两个有序的单链表
- CodeForces
- Dubbo分布式服务框架简介
- java学习初探6之继承 方法覆盖 多态
- 初识微信小程序第一弹
- 应用程序打包和发布
- Maven中的依赖传递
- Vue.js快速入门及示例
- Java 虚拟机(JVM)
- Linux必杀(十六):打包命令tar