• <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 1231 The Alphabet Game 貪心

            近來實驗室給派了新活,跟原來做的東西,以及我們熟悉的東西都比較不搭邊的,郁悶。
            折騰了兩個星期,昨天終于有了些進展。
            今天做了兩道水題~  都是貪心


            思路:
            這題看上去挺唬人,提交的人也不多,實際上都是水題來的。
            1. 對于同一種字母,求出它出現(xiàn)位置的最左邊、最右邊、最上邊、最下邊。這就構成了一個矩形。
            2. 對于在x軸上投影重合的一系列矩形,他們必定處在同一個方格內(nèi)。給這些方格編號。
            3. 對于在y軸上投影重合的一系列矩形,如果其中兩個編號相同,就不符合條件了。

            #include <stdio.h>
            #include 
            <stdlib.h>
            #include 
            <algorithm>

            using namespace std;

            struct rect {
                
            int left, right, top, bottom;
                
            int rank_x;
            }
             rec[32];
            int T, K, P;

            int cmp_x(const void *a, const void *b)
            {
                
            return ((struct rect *)a)->left - ((struct rect *)b)->left;
            }


            int cmp_y(const void *a, const void *b)
            {
                
            return ((struct rect *)a)->top - ((struct rect *)b)->top;
            }


            inline 
            int solve()
            {
                
            int i, last, rank, mask;

                qsort(rec, K, 
            sizeof(rec[0]), cmp_x);
                rank 
            = 0;
                
            for (i = 0; i < K; ) {
                    last 
            = rec[i].right;
                    
            while (i < K && rec[i].left <= last) {
                        rec[i].rank_x 
            = rank;
                        last 
            = max(last, rec[i].right);
                        i
            ++;
                    }

                    rank
            ++;
                }


                qsort(rec, K, 
            sizeof(rec[0]), cmp_y);
                
            for (i = 0; i < K; ) {
                    mask 
            = 0;
                    last 
            = rec[i].bottom;
                    
            while (i < K && rec[i].top <= last) {
                        
            if (mask & (1 << rec[i].rank_x))
                            
            return 0;
                        mask 
            |= 1 << rec[i].rank_x;
                        last 
            = max(last, rec[i].bottom);
                        i
            ++;
                    }

                }


                
            return 1;
            }


            int main()
            {
                
            int i, j, x, y;

                scanf(
            "%d"&T);
                
            while (T--{
                    scanf(
            "%d%d"&K, &P);
                    
            for (i = 0; i < K; i++{
                        rec[i].left 
            = rec[i].top = 1000000;
                        rec[i].right 
            = rec[i].bottom = 0;
                        
            for (j = 0; j < P; j++{
                            scanf(
            "%d%d"&x, &y);
                            
            if (x < rec[i].left)
                                rec[i].left 
            = x;
                            
            if (x > rec[i].right)
                                rec[i].right 
            = x;
                            
            if (y < rec[i].top)
                                rec[i].top 
            = y;
                            
            if (y > rec[i].bottom)
                                rec[i].bottom 
            = y;
                        }

                    }

                    printf(
            "%s\n", solve() ? "YES" : "NO");
                }


                
            return 0;
            }


            posted on 2010-05-24 23:14 糯米 閱讀(519) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            亚洲午夜无码AV毛片久久| 亚洲国产精品无码久久久秋霞2 | 久久九九兔免费精品6| 91精品久久久久久无码| 久久久久高潮毛片免费全部播放| 久久久久99精品成人片牛牛影视| 成人亚洲欧美久久久久| 久久精品一区二区国产| 国产精品一区二区久久精品| 久久久久久亚洲精品成人| 久久精品卫校国产小美女| 无码人妻久久一区二区三区蜜桃| 亚洲中文字幕伊人久久无码| 奇米影视7777久久精品人人爽| 精品国产乱码久久久久软件| 波多野结衣久久精品| av色综合久久天堂av色综合在| AV无码久久久久不卡蜜桃| 久久人人爽人人爽人人片AV不| 久久久av波多野一区二区| 久久国产高清字幕中文| 91久久福利国产成人精品| 久久精品国产精品亚洲| 亚洲国产精品嫩草影院久久| 色诱久久久久综合网ywww| 久久男人Av资源网站无码软件| 国产精品岛国久久久久| 久久久精品久久久久久| 久久久久久伊人高潮影院| 久久国产精品一国产精品金尊| 色综合久久最新中文字幕| 久久综合五月丁香久久激情| 久久久无码精品亚洲日韩蜜臀浪潮 | 久久亚洲精品国产精品婷婷| 中文精品久久久久人妻不卡| 久久精品国产亚洲av麻豆小说| 51久久夜色精品国产| 国产成人精品综合久久久久| 中文字幕成人精品久久不卡| 国产精品亚洲综合久久| 久久99热精品|