haha

来源:互联网 发布:sap hana sql 编辑:程序博客网 时间:2024/05/16 14:24

站操作,先预处理出最大值的位置,然后输出住最大值,再找次大值,之前如站得比次大值大的先输出,才输出次大值依次循环,直至结束

#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>int zhan[1999999],top,a[1999999],max1,pos1,maxn[1999999],pos[1999999],n;using namespace std;int main(){    scanf("%d",&n);    for(int i=1;i<=n;i++) scanf("%d",&a[i]);    for(int i=n;i>=1;i--){        if(a[i]>max1) max1=a[i],pos1=i;        maxn[i]=max1,pos[i]=pos1;    }    int head=0,tail=1,top=0;    while(tail<=n){        if(maxn[tail]>zhan[top])        while(tail<pos[tail])        zhan[++top]=a[tail++];        printf("%d ",a[tail++]);        while(maxn[tail]<zhan[top]) printf("%d ",zhan[top--]);    }} 
原创粉丝点击