• <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 閱讀(327) 評論(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
            • 評論內容較長,點擊標題查看
            • --王私江
            国产91久久综合| 久久亚洲中文字幕精品一区| 精品久久久久久亚洲精品 | 色综合久久无码中文字幕| 三上悠亚久久精品| 青青草原1769久久免费播放| 久久精品国产精品亜洲毛片| 综合久久国产九一剧情麻豆| 国产精品伦理久久久久久| 精品久久久无码人妻中文字幕| 久久久久一区二区三区| 99久久无色码中文字幕人妻| 狠狠久久综合伊人不卡| 亚洲AV无码久久精品色欲| 久久无码国产| 精品久久久久久无码中文野结衣| 欧洲精品久久久av无码电影 | 欧美精品福利视频一区二区三区久久久精品| 久久伊人五月天论坛| av无码久久久久不卡免费网站| 久久久久久免费视频| 久久久久国产一级毛片高清板 | 久久美女人爽女人爽| 久久青青草原精品国产| 狠狠色丁香久久婷婷综合图片| 久久国产精品波多野结衣AV| 久久91精品国产91久久小草| 久久天天躁狠狠躁夜夜96流白浆| 久久久精品久久久久影院| 香蕉久久影院| 国产精品久久婷婷六月丁香| 欧美国产成人久久精品| 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 国产高潮久久免费观看| 久久精品国产亚洲av水果派 | 99热热久久这里只有精品68| 精品久久久久久无码专区| 久久狠狠高潮亚洲精品| 潮喷大喷水系列无码久久精品| 久久精品亚洲精品国产色婷| 国产精品视频久久久|