• <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>

            poj1095

            Trees Made to Order
            Time Limit: 1000MS Memory Limit: 10000K
            Total Submissions: 6010 Accepted: 3459

            Description

            We can number binary trees using the following scheme:
            The empty tree is numbered 0.
            The single-node tree is numbered 1.
            All binary trees having m nodes have numbers less than all those having m+1 nodes.
            Any binary tree having m nodes with left and right subtrees L and R is numbered n such that all trees having m nodes numbered > n have either Left subtrees numbered higher than L, or A left subtree = L and a right subtree numbered higher than R.

            The first 10 binary trees and tree number 20 in this sequence are shown below:

            Your job for this problem is to output a binary tree when given its order number.

            Input

            Input consists of multiple problem instances. Each instance consists of a single integer n, where 1 <= n <= 500,000,000. A value of n = 0 terminates input. (Note that this means you will never have to output the empty tree.)

            Output

            For each problem instance, you should output one line containing the tree corresponding to the order number for that instance. To print out the tree, use the following scheme:

            A tree with no children should be output as X.
            A tree with left and right subtrees L and R should be output as (L')X(R'), where L' and R' are the representations of L and R.
            If L is empty, just output X(R').
            If R is empty, just output (L')X.

            Sample Input

            1
                        20
                        31117532
                        0

            Sample Output

            X
                        ((X)X(X))X
                        (X(X(((X(X))X(X))X(X))))X(((X((X)X((X)X)))X)X)

            Source

            不錯的題目

            考察卡特蘭數的遞歸式的

            等會把找到的卡特蘭數的資料發一篇上來


            code

            #include <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            #include 
            <cassert>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <fstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <iomanip>
            using namespace std;
            long long dx[20]={1,1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845,35357670,129644790,477638700,1767263190};
            void dg(long long n,long long k)
            {
                
            int i;
                
            long long sum;
                
            if(n==1)
                {
                    printf(
            "X");
                    
            return ;
                }
                sum
            =0;
                
            for(i=0;k>sum;i++) sum+=dx[i]*dx[n-i-1];
                i
            =i-1;
                sum
            -=dx[i]*dx[n-i-1];
                k
            -=sum;
                
            //printf("%d %d %d\n",n,k,i);
                if(i)
                {
                    printf(
            "(");
                    dg(i,(k
            -1)/dx[n-i-1]+1);//沒有也是一種
                    printf(")");
                }
                printf(
            "X");
                
            if(n-i-1)
                {
                    printf(
            "(");
                    dg(n
            -i-1,(k-1)%dx[n-i-1]+1);
                    printf(
            ")");
                }
            }
            int main()
            {
                
            int i;
                
            long long n;
                
            long long sum;
                
            while(scanf("%I64d",&n)!=EOF&&n!=0)
                {
                    
            if(n==1)
                    {
                        printf(
            "X\n");
                    }
                    
            else
                    {
                        sum
            =0;
                        
            for(i=1;n>sum;i++) sum+=dx[i];
                        i
            --;
                        sum
            -=dx[i];
                        dg(i,n
            -sum);
                        printf(
            "\n");
                    }

                }
                
            return 0;
            }

            posted on 2012-08-02 16:56 jh818012 閱讀(169) 評論(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
            • 評論內容較長,點擊標題查看
            • --王私江
            亚洲人成网亚洲欧洲无码久久| 777米奇久久最新地址| 久久se精品一区精品二区国产| 久久久久97国产精华液好用吗| 亚洲欧洲久久久精品| 人妻精品久久无码专区精东影业| 久久国产成人精品麻豆| 久久青青草原精品国产软件| 精品久久久久久中文字幕大豆网| 精品久久久久香蕉网| 亚洲第一永久AV网站久久精品男人的天堂AV| 久久久久人妻一区二区三区 | 99久久夜色精品国产网站| 三级片免费观看久久| 精品久久久久久| 久久99久国产麻精品66| 久久国产精品波多野结衣AV| 日韩精品久久无码中文字幕| 国产精品成人99久久久久 | A狠狠久久蜜臀婷色中文网| 青青草国产97免久久费观看| 久久国产精品久久精品国产| 无码国内精品久久综合88| 成人精品一区二区久久久| 精品少妇人妻av无码久久| 亚洲国产精品无码久久一区二区 | 亚洲国产成人久久一区WWW| 色噜噜狠狠先锋影音久久| 久久精品无码一区二区无码| 色妞色综合久久夜夜| 国产精品激情综合久久| 91精品国产色综久久| 久久99热国产这有精品| 久久久久人妻一区精品色| 人妻无码中文久久久久专区| 国内精品久久久久影院薰衣草| 色综合久久久久综合99| 中文字幕精品无码久久久久久3D日动漫| 国内精品久久久久久不卡影院| 国产91久久综合| 国内精品免费久久影院|