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

首頁 > 學院 > 開發(fā)設計 > 正文

Codeforces Round #398(Div. 2)A. Snacktower【模擬】

2019-11-08 02:26:00
字體:
來源:轉載
供稿:網友

A. Snacktowertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard 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 timen 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, thei-th of them equals the size of the snack which fell on thei-th day. Sizes are distinct integers from1 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 thei-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.

ExamplesInput
33 1 2Output
3 2 1Input
54 5 1 2 3Output
 5 4  3 2 1Note

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 size1 fell, and the residents weren't able to place it because they were missing the snack of size2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size1 which had fallen before.

題目大意:

給你N個數(shù)(從1-N),每次遇到剩余數(shù)字中的最大項之后,逆序將之前出現(xiàn)過的數(shù)字按照每次-1的順序輸出(就是說必須連續(xù))。

如果沒有任何數(shù)字輸出,那么輸出一個空行。

思路:

過程維護剩余數(shù)字中的最大值,然后每一次遇到,逆序模擬輸出即可。

Ac代碼:

#include<stdio.h>#include<string.h>#include<iostream>using namespace std;int a[100060];int vis[100060];int main(){    int n;    while(~scanf("%d",&n))    {        memset(vis,0,sizeof(vis));        for(int i=1;i<=n;i++)        {            scanf("%d",&a[i]);        }        int maxn=n;        int minn=0x3f3f3f3f;        for(int i=1;i<=n;i++)        {            vis[a[i]]=1;            if(a[i]!=maxn)            {                minn=min(minn,a[i]);                printf("/n");            }            else            {                int flag=0;                minn=min(minn,a[i]);                for(int j=maxn;j>=minn;j--)                {                    if(vis[j]==1)                    printf("%d ",j);                    else                    {                        flag=1;                        maxn=j;                        break;                    }                }                if(flag==0)maxn=minn-1,minn=0x3f3f3f3f;                printf("/n");            }        }    }}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 英超| 察雅县| 娄底市| 兴城市| 义马市| 涟源市| 永年县| 安图县| 常州市| 怀柔区| 沛县| 涿鹿县| 同仁县| 乃东县| 安吉县| 古交市| 吴桥县| 丹寨县| 临颍县| 普洱| 五原县| 荣成市| 盘锦市| 宜君县| 金平| 青州市| 香格里拉县| 阳新县| 黑河市| 贡嘎县| 滨州市| 吕梁市| 阿图什市| 方山县| 黄陵县| 偏关县| 临漳县| 东丰县| 滦南县| 万源市| 禹州市|