• <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 1048 Follow My Logic 有意思的題

            這題很有意思哇。給出一個這樣的東西:
            A---+
                |   
                +---:\
                    : >o---:\
                +---:/     : )---?
                |      C--o:/
            B---+

            其中:
                    :\               :\                 -:\                 -o:\                       A-o:\
                    : )              : >                 : )-                 : )o-                       : )o-?
                    :/               :/                 -:/                 --:/                       B--:/
               
                 AND gate          OR gate       Gate with inputs    An inverted top input          Two logic input
                                                                     and an inverted output         and the output


            然后叫你分析它的輸出。
            其實哥比較喜歡這種有創意的題,做這種題代碼也寫得比較有意思。


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

            struct node {
                
            char type, n[3];
                
            struct node *child[2];
            }
            ;
            struct node nodes[128], *root;
            int nodes_cnt;
            char map[128][128], input[32];
            int W[128], H;

            int in_range(int dx, int dy)
            {
                
            return !(dx < 0 || dx >= W[dy] || dy < 0 || dy >= H);
            }


            void follow_path(int x, int y, struct node **p_node);

            int find_node(int x, int y, struct node **p_node)
            {
                
            struct node *t;

                
            if (map[y][x] >= 'A' && map[y][x] <= 'Z'{
                    t 
            = &nodes[nodes_cnt++];
                    t
            ->type = map[y][x];
                    
            *p_node = t;
                    
            return 1;
                }

                
            if (map[y][x] == 'o')
                    x
            --;
                
            if (map[y][x] == ')' || map[y][x] == '>'{
                    t 
            = &nodes[nodes_cnt++];
                    memset(t, 
            0sizeof(*t));
                    t
            ->type = map[y][x];
                    
            *p_node = t;
                    
            if (in_range(x - 3, y - 1&& map[y - 1][x - 3== 'o')
                        t
            ->n[0= 1;
                    
            if (in_range(x - 3, y + 1&& map[y + 1][x - 3== 'o')
                        t
            ->n[1= 1;
                    
            if (in_range(x + 1, y) && map[y][x + 1== 'o')
                        t
            ->n[2= 1;
                    follow_path(x 
            - 3, y - 1&t->child[0]);
                    follow_path(x 
            - 3, y + 1&t->child[1]);
                    
            return 1;
                }


                
            return 0;
            }


            void follow_path(int x, int y, struct node **p_node)
            {
                
            int i, dx, dy;
                
            const struct {
                    
            char ch;
                    
            int dx, dy;
                }
             dir[4= {
                    
            {'-'-10},
                    
            {'-'10},
                    
            {'|'01},
                    
            {'|'0-1}
                }
            ;

                
            while (1{
                    
            for (i = 0; i < 4; i++{
                        dx 
            = x + dir[i].dx;
                        dy 
            = y + dir[i].dy;
                        
            if (!in_range(dx, dy))
                            
            continue;
                        
            if (map[dy][dx] == dir[i].ch || map[dy][dx] == '+')
                            
            break;
                        
            if (find_node(dx, dy, p_node))
                            
            return ;
                    }

                    
            if (i == 4)
                        
            break;
                    map[y][x] 
            = '.';
                    x 
            = dx;
                    y 
            = dy;
                }


                
            *p_node = NULL;
            }


            int calc(struct node *t)
            {
                
            if (!t)
                    
            return 0;
                
            if (t->type >= 'A' && t->type <= 'Z')
                    
            return input[t->type - 'A'- '0';
                
            if (t->type == ')'
                    
            return ((calc(t->child[0]) ^ t->n[0]) & 
                            (calc(t
            ->child[1]) ^ t->n[1])) ^
                           t
            ->n[2];
                
            if (t->type == '>')
                    
            return ((calc(t->child[0]) ^ t->n[0]) | 
                            (calc(t
            ->child[1]) ^ t->n[1])) ^
                           t
            ->n[2];
                
            return 0;
            }


            void find_root()
            {
                
            int x, y;

                root 
            = NULL;
                
            for (y = 0; y < H; y++
                
            for (x = 0; x < W[y]; x++{
                    
            if (map[y][x] == '?'{
                        follow_path(x, y, 
            &root);
                        
            return ;
                    }

                }

            }


            int main()
            {

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

                
            while (1{
                    nodes_cnt 
            = 0;
                    H 
            = 0;
                    
            while (1{
                        
            if (!fgets(map[H], sizeof(map[H]), stdin))
                            
            return 0;
                        
            if (map[H][0== '*')
                            
            break;
                        W[H] 
            = strlen(map[H]);
                        H
            ++;
                    }

                    find_root();
                    
            while (1{
                        fgets(input, 
            sizeof(input), stdin);
                        
            if (input[0== '*')
                            
            break;
                        printf(
            "%d\n", calc(root));
                    }

                    printf(
            "\n");
                }


                
            return 0;
            }

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

            久久九九兔免费精品6| 久久精品成人国产午夜| 久久嫩草影院免费看夜色| 色偷偷88欧美精品久久久| 亚洲香蕉网久久综合影视| 成人资源影音先锋久久资源网| 国内精品伊人久久久久影院对白| 麻豆精品久久久久久久99蜜桃 | 91久久精品电影| 亚洲欧美一区二区三区久久| 精品亚洲综合久久中文字幕| 中文字幕无码av激情不卡久久| 91久久婷婷国产综合精品青草| 久久99热这里只频精品6| 久久精品国产69国产精品亚洲| 久久久久亚洲精品日久生情| 中文字幕一区二区三区久久网站| 亚洲国产精品无码久久一区二区 | 日本久久久久久中文字幕| 欧美精品国产综合久久| 国产精品午夜久久| 久久国产热精品波多野结衣AV| 亚洲国产小视频精品久久久三级| 亚洲国产精品久久久久婷婷老年| 午夜久久久久久禁播电影| 伊人色综合久久天天人守人婷| 精品久久久久中文字| 国产99久久久国产精免费| 粉嫩小泬无遮挡久久久久久| 久久天天躁狠狠躁夜夜2020一| 久久亚洲国产精品123区| 99精品伊人久久久大香线蕉| 精品久久香蕉国产线看观看亚洲 | 久久99亚洲综合精品首页| 奇米影视7777久久精品| 少妇熟女久久综合网色欲| 亚洲综合久久夜AV | 久久国产欧美日韩精品免费| 久久天天躁狠狠躁夜夜2020老熟妇 | 精品久久久久久无码免费| 国产高潮国产高潮久久久91|