• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            poj1068

            Parencodings
            Time Limit: 1000MS
            Memory Limit: 10000K
            Total Submissions: 13525
            Accepted: 8049

            Description

            Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:
            q By an integer sequence P = p1 p2...pn where pi is the number of left parentheses before the ith right parenthesis in S (P-sequence).
            q By an integer sequence W = w1 w2...wn where for each right parenthesis, say a in S, we associate an integer which is the number of right parentheses counting from the matched left parenthesis of a up to a. (W-sequence).

            Following is an example of the above encodings:

            S (((()()())))
            P-sequence 4 5 6666
            W-sequence 1 1 1456

            Write a program to convert P-sequence of a well-formed string to the W-sequence of the same string.

            Input

            The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case is an integer n (1 <= n <= 20), and the second line is the P-sequence of a well-formed string. It contains n positive integers, separated with blanks, representing the P-sequence.

            Output

            The output file consists of exactly t lines corresponding to test cases. For each test case, the output line should contain n integers describing the W-sequence of the string corresponding to its given P-sequence.

            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

            有點亂,感覺方法好多,就是不知道怎么寫……
             1 #include<stdio.h>
             2 #include<string.h>
             3 #include<math.h>
             4 int t,n,a[30];
             5 int sec,i,j,k,top;
             6 int stack[50],ans[50];
             7 void printtest()
             8 {
             9     int i;
            10     for (i=1;i<=top ;i++ )
            11         if (stack[i]==-1) printf("(");
            12     else printf(")");
            13 }
            14 int main()
            15 {
            16     scanf("%d",&t);
            17     for (j=1;j<=t ;j++ )
            18     {
            19         scanf("%d",&n);
            20         a[0]=0;
            21         top=0;
            22         for (i=1;i<=n ;i++ )
            23         {
            24             scanf("%d",&a[i]);
            25             if (a[i]!=a[i-1])
            26             {
            27                 for (k=a[i-1]+1;k<=a[i] ;k++ )
            28                 {
            29                     top++;
            30                     stack[top]=-1;//-1表示右括號
            31                 }
            32                 top++;
            33                 stack[top]=1;//1表示左括號
            34             }
            35             else 
            36             {
            37                 top++;
            38                 stack[top]=1;
            39             }
            40         }
            41         //printtest();//檢查
            42         ans[0]=0;
            43         for (i=1;i<=top ;i++ )
            44         if (stack[i]==1)
            45         {
            46             sec=1;
            47             k=i-1;
            48             while (sec!=0
            49             {
            50                 sec=sec+stack[k];
            51                 k--;
            52             }
            53             ans[0]++;
            54             ans[ans[0]]=(i-k+1)/2;
            55         }
            56         for (i=1;i<ans[0] ;i++ ) printf("%d ",ans[i]);
            57         printf("%d\n",ans[ans[0]]);
            58     }
            59     return 0;
            60 }
            61 

            posted on 2012-02-01 13:20 jh818012 閱讀(328) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內容較長,點擊標題查看
            • --王私江
            欧美与黑人午夜性猛交久久久| 99久久中文字幕| 精品一久久香蕉国产线看播放| 国产精品禁18久久久夂久| 亚洲AV无码久久精品成人| 久久久国产精华液| 久久久婷婷五月亚洲97号色| 久久男人AV资源网站| 国产精品乱码久久久久久软件| 国产69精品久久久久9999APGF | 亚洲中文字幕无码久久精品1| 日本久久久久亚洲中字幕| 99久久亚洲综合精品成人| 青青草原综合久久大伊人导航| 久久人爽人人爽人人片AV| 久久中文字幕视频、最近更新| 无码国内精品久久人妻| 色偷偷88欧美精品久久久| av国内精品久久久久影院| 一极黄色视频久久网站| 国产激情久久久久影院老熟女| 国内精品伊人久久久久妇| 久久精品国产亚洲精品| 久久久精品2019免费观看| 亚洲欧美成人久久综合中文网| 国内精品伊人久久久久网站| 国产午夜精品久久久久免费视 | 国产美女久久久| 亚洲国产精品无码久久久秋霞2| 欧美日韩中文字幕久久久不卡| 香蕉久久夜色精品国产小说| 精品国产VA久久久久久久冰| 国产成人精品综合久久久| 伊色综合久久之综合久久| 狠狠久久综合伊人不卡| 国产午夜精品理论片久久| 99精品久久精品| 香蕉久久一区二区不卡无毒影院| 久久精品成人免费看| 久久精品国产91久久麻豆自制| AV无码久久久久不卡蜜桃|