标签:poj bin string idt 复杂度 结果 pos ++ 输出
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 26686 | Accepted: 15645 | 
Description
S (((()()())))
P-sequence 4 5 6666
W-sequence 1 1 1456
Input
Output
Sample Input
2 6 4 5 6 6 6 6 9 4 6 6 6 6 8 9 9 9
Sample Output
1 1 1 4 5 6 1 1 2 4 5 1 1 3 9
Source
#include<iostream>
#include<cstring>
#include<cstdio>
#include<stack>
#include<algorithm>
using namespace std;
inline int read(){
    int x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c==‘-‘) f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-‘0‘;
    return x*f;       
}
int N;
int P[1001];
int ans[1001];
stack<int> sta;
stack<int> k;
int main(){
    int T=read();
    while(T--){
        stack<int> sta;
        stack<int> k;
        N=read();
        for(int i=1;i<=N;i++){
            P[i]=read();
            if(P[i]!=P[i-1]){
               ans[i]=1;
               if(P[i]-P[i-1]!=1) sta.push(P[i]-P[i-1]-1),k.push(i);
            }
            else{
                int s=sta.top();
                sta.pop();
                ans[i]=i-k.top()+1;
                if(s-1!=0) sta.push(s-1);
                else k.pop();
            }
        }
        for(int i=1;i<N;i++)
            printf("%d ",ans[i]);
        printf("%d\n",ans[N]);
    }
}
标签:poj bin string idt 复杂度 结果 pos ++ 输出
原文地址:http://www.cnblogs.com/wxjor/p/6974129.html