国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

【Codeforces 767 A. Snacktower】

2019-11-08 02:44:33
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

A. Snacktower time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output 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.

Examples input 3 3 1 2 output 3

2 1 input 5 4 5 1 2 3 output

5 4

3 2 1 Note 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.

每次要先把最大的吃過(guò)后才能吃小的,如果今天能吃的不是剩余的最大的,今天便不能吃東西?

AC代碼:

#include<cstdio>#include<algorithm>using namespace std;const int K = 1e5 + 10;typedef long long LL;int a[K],vis[K];int main(){ int N; scanf("%d",&N); for(int i = 1 ; i <= N; i++) scanf("%d",&a[i]); int nl = N; for(int i = 1 ; i <= N; i++){ if(a[i] != nl) printf("/n"); vis[a[i]] = 1; if(vis[nl]){ while(vis[nl]){ printf("%d ",nl); nl--; } printf("/n"); } } return 0;}
上一篇:wpf之旅

下一篇:魔幻數(shù)字47

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 江门市| 石屏县| 彩票| 新竹县| 历史| 聊城市| 额尔古纳市| 平安县| 田林县| 博乐市| 长阳| 邵阳县| 广德县| 蛟河市| 柳林县| 龙胜| 武宁县| 紫云| 北票市| 南阳市| 太谷县| 霍城县| 北票市| 循化| 岗巴县| 内丘县| 汉源县| 长丰县| 鲁山县| 正阳县| 陆川县| 阳朔县| 府谷县| 堆龙德庆县| 宿迁市| 香港| 高尔夫| 贺州市| 肃北| 淮南市| 万源市|