• <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
            數據加載中……

            POJ 1478 Island of Logic 枚舉

            思路:
            由于數據量比較小,可以枚舉ABCDE的所有身份和時間(白天或者晚上),不會超時。
            判斷deducible、impossible的部分很難寫,基本上是照著數據改的。。
            1. 如果沒有任何狀態是符合要求的,輸出 impossible。
            2. 在符合要求的狀態中,如果對于某個人的身份或者時間,存在分歧,那該條就不能輸出。
            3. 在(2)的情況下,如果沒有任何輸出,就輸出 deducible。

            快被這玩意整瘋了。要是沒有數據肯定搞不出來。


            #include <stdio.h>

            #define MAX_N 6

            enum kind_t {
                NONE, 
                
                ROLE_START, 
                DIVINE 
            = ROLE_START, HUMAN, EVIL, 
                ROLE_END 
            = EVIL,
                ANY_ROLE,

                LYING, 
                
                TIME_START, 
                DAY 
            = TIME_START, 
                NIGHT, 
                TIME_END 
            = NIGHT,
                ANY_TIME
            }
            ;

            char *str_tbl[] = 
                
            "none"
                
            "divine""human""evil""any_role"
                
            "lying"
                
            "day""night""any_time"
            }
            ;

            struct node {
                
            int x, y, not, type;
            }
            ;
            struct node in[64];

            struct stat {
                
            int role[MAX_N], time;
            }
            ;
            struct stat ans, cur;

            int N;

            __inline 
            void input(struct node *t)
            {
                
            char a[32], b[32];

                scanf(
            "%s%s", a, b);
                t
            ->= a[0- 'A';
                
            if (b[0== 'I')
                    t
            ->= t->x;
                
            else
                    t
            ->= b[0- 'A';
                scanf(
            "%s%s", a, b);
                
            if (b[0== 'n' && b[1== 'o'{
                    t
            ->not = 1;
                    scanf(
            "%s", b);
                }
             else 
                    t
            ->not = 0;
                
            if (b[0== 'd')
                    t
            ->type = (b[1== 'a'? DAY : DIVINE;
                
            else if (b[0== 'h')
                    t
            ->type = HUMAN;
                
            else if (b[0== 'e')
                    t
            ->type = EVIL;
                
            else if (b[0== 'l')
                    t
            ->type = LYING;
                
            else 
                    t
            ->type = NIGHT;
            }


            __inline 
            int lies(int x)
            {
                
            return (cur.role[x] == EVIL) || (cur.role[x] == HUMAN && cur.time == NIGHT);
            }


            __inline 
            int check_one(struct node *t)
            {
                
            int right;

                
            if (t->type >= ROLE_START && t->type <= ROLE_END)
                    right 
            = t->not ^ (cur.role[t->y] == t->type);
                
            else if (t->type == LYING)
                    right 
            = t->not ^ lies(t->y);
                
            else {
                    
            if (t->type == DAY)
                        right 
            = (cur.time == DAY);
                    
            else
                        right 
            = (cur.time == NIGHT);
                }


                
            return lies(t->x) ? !right : right;
            }


            __inline 
            void check()
            {
                
            int i;

                
            for (i = 0; i < N; i++
                    
            if (!check_one(&in[i]))
                        
            return ;

                
            for (i = 0; i < MAX_N; i++{
                    
            if (ans.role[i] == NONE)
                        ans.role[i] 
            = cur.role[i];
                    
            else if (ans.role[i] != cur.role[i])
                        ans.role[i] 
            = ANY_ROLE;
                }

                
            if (ans.time == NONE)
                    ans.time 
            = cur.time;
                
            else if (ans.time != cur.time)
                    ans.time 
            = ANY_TIME;
            }


            __inline 
            void solve()
            {
                
            int i, mask, cnt, *arr[MAX_N];

                mask 
            = 0;
                
            for (i = 0; i < N; i++{
                    mask 
            |= 1 << in[i].x;
                    mask 
            |= 1 << in[i].y;
                }


                
            for (cnt = i = 0; i < MAX_N; i++{
                    
            if (mask & (1 << i)) {
                        arr[cnt
            ++= &cur.role[i];
                        cur.role[i] 
            = ROLE_START;
                    }
             else
                        cur.role[i] 
            = NONE;
                    ans.role[i] 
            = NONE;
                }

                ans.time 
            = NONE;

                
            while (1{
                    cur.time 
            = DAY;
                    check();
                    cur.time 
            = NIGHT;
                    check();
                    
            for (i = 0; i < cnt && *arr[i] == ROLE_END; i++)
                        
            *arr[i] = ROLE_START;
                    
            if (i == cnt)
                        
            break;
                    (
            *arr[i])++;
                }

            }


            __inline 
            void dump()
            {
                
            int i, cnt;

                
            for (i = 0; i < MAX_N && ans.role[i] == NONE; i++);
                
            if (i == MAX_N && ans.time == NONE) {
                    printf(
            "This is impossible.\n\n");
                    
            return ;
                }


                
            for (cnt = i = 0; i < MAX_N; i++{
                    
            if (ans.role[i] >= ROLE_START && ans.role[i] <= ROLE_END) {
                        cnt
            ++;
                        printf(
            "%c is %s.\n", i + 'A', str_tbl[ans.role[i]]);
                    }

                }
                
                
            if (ans.time >= TIME_START && ans.time <= TIME_END) {
                    printf(
            "It is %s.\n", str_tbl[ans.time]);
                    cnt
            ++;
                }


                
            if (!cnt) {
                    printf(
            "No facts are deducible.\n\n");
                    
            return ;
                }


                putchar(
            '\n');
            }


            int main()
            {
                
            int i, t;

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

                
            for (t = 1; scanf("%d"&N), N; t++{
                    
            for (i = 0; i < N; i++)
                        input(
            &in[i]);
                    printf(
            "Conversation #%d\n", t);
                    solve();
                    dump();
                }


                
            return 0;
            }

            posted on 2010-03-30 16:42 糯米 閱讀(542) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            天堂无码久久综合东京热| 国产69精品久久久久99| 亚洲精品白浆高清久久久久久 | 久久99精品国产自在现线小黄鸭 | 亚洲国产精品无码久久久久久曰| 欧美亚洲日本久久精品| 亚洲精品无码久久千人斩| 久久er国产精品免费观看2| 久久久WWW免费人成精品| 久久亚洲精品成人av无码网站| 91超碰碰碰碰久久久久久综合| 亚洲欧美精品一区久久中文字幕 | 久久久人妻精品无码一区 | 久久久午夜精品| 久久国产高潮流白浆免费观看| 很黄很污的网站久久mimi色| 色欲久久久天天天综合网精品 | 久久综合九色欧美综合狠狠| 久久精品人成免费| 久久精品国产亚洲AV香蕉| 久久综合综合久久97色| 久久夜色精品国产噜噜噜亚洲AV| 久久久青草青青国产亚洲免观| 9191精品国产免费久久| 91久久婷婷国产综合精品青草| 国产成人无码精品久久久性色| 久久93精品国产91久久综合| 国产精品视频久久久| 97精品伊人久久大香线蕉app| 久久精品免费全国观看国产| 国产精品99久久不卡| 99热成人精品热久久669| 日本强好片久久久久久AAA| 区久久AAA片69亚洲| 久久伊人亚洲AV无码网站| 国产精品一区二区久久精品无码| 国产亚洲婷婷香蕉久久精品| 狠狠88综合久久久久综合网| 国产成人久久激情91| 久久精品国产亚洲AV无码娇色| 久久国产色AV免费观看|