• <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>
            posts - 74,  comments - 33,  trackbacks - 0

            1029 Russian Dolls

            TimeLimit : 1 Second   Memorylimit : 32 Megabyte   Special Judge

            Totalsubmit : 68   Accepted : 15

            Russian nesting dolls are brightly painted hollow wooden figures. The dolls in a set have roughly the same shape, typically humanoid, but different sizes. When the set is assembled, the biggest doll contains the second-biggest doll, the second-biggest contains the third-biggest, and so on.

            We can approximate the shape of a doll as a cylinder of height h, diameter d, and wall thickness w. Such a doll would have a hollow of height h-2w and diameter d-2w.

            Boris and Natasha each has a set of dolls. The sets are nearly identical; each has the same number of dolls, which look the same but differ in their dimensions. Last night Boris and Natasha were playing with their dolls and left them in the living room. Their mother tidied them away, dumping them all in one box. Can you help Boris and Natasha separate their sets of dolls?


            Input

            Standard Input will consist of several test cases. The first line of each test case will contain n, the number of dolls in each set (1 < n <= 100). 2n lines follow; each gives the dimensions, h, d, w of a different doll (h,d >= 2w > 0). A line containing 0 follows the last test case.


            Output

            For each test case, separate the dolls into two sets of nesting dolls such that, within each set, the dolls fit within each other, standing straight up, as described above. The first n lines of output should give the dimensions of the dolls in one set, in decreasing order by height. The next line should contain a single hyphen, "-". The next n lines should give the dimensions of the dolls in the second set, also in decreasing order by height. There will always be a solution. If there are many solutions, any will do. Output an empty line between test cases.


            Sample Input

            3
            100 100 3
            97 97 3
            94 94 3
            91 91 3
            88 88 3
            85 85 3
            5
            100 100 1
            97 97 3
            98 98 1
            96 96 1
            94 94 1
            92 92 1
            90 90 1
            88 88 1
            86 86 1
            84 84 1
            0


            Sample Output

            100 100 3
            94 94 3
            88 88 3
            -
            97 97 3
            91 91 3
            85 85 3

            100 100 1
            98 98 1
            96 96 1
            94 94 1
            92 92 1
            -
            97 97 3
            90 90 1
            88 88 1
            86 86 1
            84 84 1



            分別給出2*N個套娃的 高,直徑,內(nèi)壁厚度。
            要求從這2*N個中分出兩套套娃來。
            xjm說是DP,不過我按照我的搜索思路也過了。


            #include <stdio.h>
            #include 
            <algorithm>
            using namespace std;

            struct doll
            {
                
            int h,d,w;    
            }
            ;
            doll all[
            200];
            int a[100],b[100],n;

            bool cmp(doll a,doll b)
            {
                
            if(a.h!=b.h)
                    
            return a.h>b.h;
                
            else
                    
            return a.d>b.d;    
            }


            bool dfs(int p1,int p2,int p)
            {
                
            if(p1==n&&p2==n) return true;
                
            int x;
                
            if(p1==n)
                
            {
                    
            if(p2==0)
                    
            {
                        b[p2]
            =p;
                        p2
            ++;
                        p
            ++;
                        
            if(dfs(p1,p2,p))
                            
            return true;
                        p2
            --;
                        p
            --;
                    }

                    
            else
                    
            {
                        x
            =b[p2-1];
                        
            if(all[x].d-2*all[x].w>=all[p].d&&all[x].h-2*all[x].w>=all[p].h)
                        
            {
                            b[p2]
            =p;
                            p2
            ++;
                            p
            ++;
                            
            if(dfs(p1,p2,p))
                                
            return true;
                            p1
            --;
                            p
            --;    
                        }
                
                    }

                    
            return false;
                }

                
            if(p2==n)
                
            {
                    
            if(p1==0)
                    
            {
                        a[p1]
            =p;
                        p1
            ++;
                        p
            ++;
                        
            if(dfs(p1,p2,p))
                            
            return true;
                        p1
            --;
                        p
            --;
                    }

                    
            else
                    
            {
                        x
            =a[p1-1];
                        
            if(all[x].d-2*all[x].w>=all[p].d&&all[x].h-2*all[x].w>=all[p].h)
                        
            {
                            a[p1]
            =p;
                            p1
            ++;
                            p
            ++;
                            
            if(dfs(p1,p2,p))
                                
            return true;
                            p1
            --;
                            p
            --;    
                        }
                
                    }

                    
            return false;            
                }

                
            if(p1!=0)
                
            {
                    x
            =a[p1-1];
                    
            if(all[x].d-2*all[x].w>=all[p].d&&all[x].h-2*all[x].w>=all[p].h)
                    
            {
                        a[p1]
            =p;
                        p1
            ++;
                        p
            ++;
                        
            if(dfs(p1,p2,p))
                            
            return true;
                        p1
            --;
                        p
            --;
                    }

                }

                
            else
                
            {
                    a[p1]
            =p;
                    p1
            ++;
                    p
            ++;
                    
            if(dfs(p1,p2,p))
                        
            return true;
                    p1
            --;
                    p
            --;
                }

                
            if(p2!=0)
                
            {
                    x
            =b[p2-1];
                    
            if(all[x].d-2*all[x].w>=all[p].d&&all[x].h-2*all[x].w>=all[p].h)
                    
            {
                        b[p2]
            =p;
                        p2
            ++;
                        p
            ++;
                        
            if(dfs(p1,p2,p))
                            
            return true;
                        p2
            --;
                        p
            --;
                    }

                }

                
            else
                
            {
                    b[p2]
            =p;
                    p2
            ++;
                    p
            ++;
                    
            if(dfs(p1,p2,p))
                        
            return true;
                    p2
            --;
                    p
            --;
                }

                
            return false;
            }


            int main()
            {
                
            int i,j;
                
            while(scanf("%d",&n)&&n)
                
            {
                    
            for(i=0;i<2*n;i++)
                        scanf(
            "%d %d %d",&all[i].h,&all[i].d,&all[i].w);
                    sort(all,all
            +2*n,cmp);
                    dfs(
            0,0,0);
                    
            for(i=0;i<n;i++)
                        printf(
            "%d %d %d\n",all[a[i]].h,all[a[i]].d,all[a[i]].w);
                    printf(
            "-\n");
                    
            for(i=0;i<n;i++)
                        printf(
            "%d %d %d\n",all[b[i]].h,all[b[i]].d,all[b[i]].w);
                    printf(
            "\n");            
                }

                
            return 0;    
            }

            posted on 2008-12-31 20:12 KNIGHT 閱讀(317) 評論(0)  編輯 收藏 引用

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            <2008年12月>
            30123456
            78910111213
            14151617181920
            21222324252627
            28293031123
            45678910

            常用鏈接

            留言簿(8)

            隨筆檔案

            文章檔案

            Friends

            OJ

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            av国内精品久久久久影院| 9999国产精品欧美久久久久久| 国产A级毛片久久久精品毛片| 国产一区二区精品久久岳| 久久亚洲国产成人影院网站| 一本久久a久久精品亚洲| 久久精品国产亚洲欧美| 亚洲午夜福利精品久久| 久久久久人妻一区精品性色av | 国产成人精品久久亚洲高清不卡 | 久久久久国产日韩精品网站| 亚洲AV无码1区2区久久| 久久黄视频| 丁香五月网久久综合| 日产精品久久久久久久| 国产激情久久久久影院小草| 亚洲综合精品香蕉久久网| 久久免费香蕉视频| 国产精品久久久久久福利漫画| 久久人人超碰精品CAOPOREN| 国产∨亚洲V天堂无码久久久| 日韩人妻无码一区二区三区久久99| 91精品国产色综久久| aaa级精品久久久国产片| 国产亚洲精久久久久久无码77777 国产亚洲精品久久久久秋霞 | 久久久精品人妻无码专区不卡| 久久久久久午夜成人影院| 思思久久99热只有频精品66| 国产三级精品久久| 中文字幕亚洲综合久久2| 久久大香香蕉国产| 久久久久人妻一区二区三区vr | 久久亚洲精品人成综合网| 欧美性大战久久久久久| 国产—久久香蕉国产线看观看| 99久久无码一区人妻a黑| 天天爽天天狠久久久综合麻豆| 日产精品99久久久久久| 久久精品国产亚洲AV麻豆网站| 亚洲va久久久噜噜噜久久狠狠| 久久亚洲中文字幕精品有坂深雪|