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

            糯米

            TI DaVinci, gstreamer, ffmpeg
            隨筆 - 167, 文章 - 0, 評論 - 47, 引用 - 0
            數(shù)據(jù)加載中……

            POJ 1058 The Gourmet Club 暴搜

            題目大意:
            16個人舉行宴席,4人一桌,一共5次。(嚴重不符合客觀事實。。)
            求怎樣安排才能使每次吃飯時,每個人的同桌都是不同的人。
            也就是說吃完5次飯下來,每個人都認識其他人了。。
            有人幫你算好了前3次的情況,你需要接著算出余下的2次,當然也有可能算不出來。

            思路:
            暴搜,位操作輔助。

            ps:
            此題描述得不大清楚,導(dǎo)致屢次wa。
            注意:
            1.多case
            2.如果有解,需要打印5行。
            3.如果無解,只需要打印“... impossible ...”

            #include <stdio.h>
            #include 
            <string.h>

            int map[16];
            int bit_cnt[256];

            __inline 
            int calc_cnt(unsigned short val)
            {
                
            return bit_cnt[val & 0xff+ 
                       bit_cnt[(val 
            >> 8)];
            }


            struct {
                
            int a, b, c;
            }
             stat[20= {
                
            {012},
                
            {013},
                
            {014},
                
            {015},

                
            {023},
                
            {024},
                
            {025},

                
            {034},
                
            {035},

                
            {045},

                
            {123},
                
            {124},
                
            {125},

                
            {134},
                
            {135},

                
            {145},

                
            {234},
                
            {235},

                
            {245},

                
            {345},
            }
            ;

            char input[1024];
            char ans[32];

            int dfs(intint);

            __inline 
            int can(int a, int b, int c, int d, int used, int step)
            {
                
            int sa, sb, sc, sd, mask;

                mask 
            = (1 << a) | (1 << b) | (1 << c) | (1 << d);
                
            if (used & mask)
                    
            return 0;
                
            if ((map[a] & mask) != (1 << a))
                    
            return 0;
                
            if ((map[b] & mask) != (1 << b))
                    
            return 0;
                
            if ((map[c] & mask) != (1 << c))
                    
            return 0;
                sa 
            = map[a];
                sb 
            = map[b];
                sc 
            = map[c];
                sd 
            = map[d];
                map[a] 
            |= mask;
                map[b] 
            |= mask;
                map[c] 
            |= mask;
                map[d] 
            |= mask;
                ans[step] 
            = a + 'A';
                ans[step 
            + 1= b + 'A';
                ans[step 
            + 2= c + 'A';
                ans[step 
            + 3= d + 'A';
                
            if (dfs(used | mask, step + 4))
                    
            return 1;
                map[a] 
            = sa;
                map[b] 
            = sb;
                map[c] 
            = sc;
                map[d] 
            = sd;
                
            return 0;
            }


            int dfs(int used, int step)
            {
                
            int i, j, d, arr[6];

                
            if (step == 32{
                    
            for (i = 0; i < 12; i++{
                        printf(
            "%.4s "&input[i*4]);
                        
            if ((i&3== 3)
                            printf(
            "\n");
                    }

                    
            for (i = 0; i < 8; i++{
                        printf(
            "%.4s "&ans[i*4]);
                        
            if ((i&3== 3)
                            printf(
            "\n");
                    }

                    
            return 1;
                }


                
            if (used == 0xffff
                    
            return dfs(0, step);

                
            for (d = 0; d < 16; d++)
                    
            if (!(used & (1 << d)))
                        
            break;
                j 
            = 0;
                
            for (i = 0; i < 16; i++)
                    
            if (!(map[d] & (1 << i)))
                        arr[j
            ++= i;

                
            if (j == 6{
                    
            for (i = 0; i < 20; i++
                        
            if (can(arr[stat[i].a], arr[stat[i].b], arr[stat[i].c], d, used, step))
                            
            return 1;        
                }
             else if (j == 3{
                    
            if (can(arr[0], arr[1], arr[2], d, used, step))
                        
            return 1;
                }
             else
                    
            *(int *)NULL = 0;

                
            return 0;
            }


            int solve()
            {
                
            int i;

                
            for (i = 0; i < 16; i++{
                    
            if (calc_cnt(map[i]) < 10)
                        
            return 0;
                }


                
            return dfs(00);
            }


            int main()
            {
                
            int i, j, k, mask;
                
            char *str;

                freopen(
            "e:\\test\\in.txt""r", stdin);

                
            for (i = 0; i < 256; i++{
                    k 
            = 0;
                    
            for (j = i; j; j &= j - 1)
                        k
            ++;
                    bit_cnt[i] 
            = k;
                }


                
            while (1{
                    memset(map, 
            0sizeof(map));
                    str 
            = input;
                    
            for (i = 0; i < 12; i++{
                        
            if (scanf("%s", str) == EOF)
                            
            return 0;
                        mask 
            = 0;
                        
            for (j = 0; j < 4; j++)
                            mask 
            |= 1 << (str[j] - 'A');
                        
            for (j = 0; j < 4; j++)
                            map[str[j] 
            - 'A'|= mask;
                        str 
            += 4;
                    }


                    
            if (!solve())
                        printf(
            "It is not possible to complete this schedule.\n");
                    printf(
            "\n");
                }


                
            return 0;
            }

            posted on 2010-02-13 21:35 糯米 閱讀(431) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            久久国产劲爆AV内射—百度| 久久综合狠狠综合久久综合88| 伊人久久免费视频| 久久激情亚洲精品无码?V| 国产精品99久久久精品无码| 国产产无码乱码精品久久鸭| 国内精品久久久久久久涩爱 | 99久久精品免费看国产免费| 亚洲精品国精品久久99热| 国产91久久精品一区二区| 久久91精品国产91久| 国产精品无码久久四虎| 久久发布国产伦子伦精品 | 久久这里只精品99re66| 国产成人精品久久| 97久久精品午夜一区二区| 狠狠色丁香久久婷婷综合图片| 国产精品久久久久天天影视| 久久久久久久精品成人热色戒 | 午夜精品久久久久久中宇| 青青热久久国产久精品 | 午夜精品久久影院蜜桃| 99久久国产主播综合精品| 99久久这里只有精品| 精品久久久久久成人AV| 亚洲AV无一区二区三区久久| 久久久久青草线蕉综合超碰| 少妇人妻综合久久中文字幕| 久久夜色精品国产www| 久久久亚洲精品蜜桃臀| 亚洲国产天堂久久综合网站| 久久这里只精品国产99热| 久久精品国产亚洲网站| 欧美777精品久久久久网| 麻豆精品久久久一区二区| 久久天堂电影网| 久久久久久极精品久久久| 久久国产亚洲精品| 久久久久久国产精品无码下载| 久久综合给合久久国产免费| 精品久久人妻av中文字幕|