• <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, 評(píng)論 - 47, 引用 - 0
            數(shù)據(jù)加載中……

            POJ 1231 The Alphabet Game 貪心

            近來(lái)實(shí)驗(yàn)室給派了新活,跟原來(lái)做的東西,以及我們熟悉的東西都比較不搭邊的,郁悶。
            折騰了兩個(gè)星期,昨天終于有了些進(jìn)展。
            今天做了兩道水題~  都是貪心


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

            #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 糯米 閱讀(522) 評(píng)論(0)  編輯 收藏 引用 所屬分類: POJ

            亚洲精品成人网久久久久久| 久久久久亚洲AV成人片| 精品久久久久久99人妻| 久久久久av无码免费网| 久久精品国产久精国产思思| 国産精品久久久久久久| 精产国品久久一二三产区区别 | 人人狠狠综合久久亚洲88| 久久国产成人午夜aⅴ影院| 午夜久久久久久禁播电影| 久久亚洲欧美日本精品| 久久这里只有精品18| 人妻精品久久久久中文字幕 | 欧美粉嫩小泬久久久久久久| 久久国产色AV免费观看| 亚洲欧美国产精品专区久久| 亚洲国产成人久久精品动漫| 久久精品中文字幕一区| 久久综合成人网| 国产精品免费久久| 久久青青草原国产精品免费| 久久久无码精品亚洲日韩蜜臀浪潮| 亚洲国产综合久久天堂| 久久精品国产72国产精福利| 日韩精品久久久久久| 久久久久亚洲AV无码网站| 亚洲人成精品久久久久| 久久久这里只有精品加勒比| 青青草原综合久久大伊人导航| 嫩草影院久久99| 国产高清国内精品福利99久久| 精品久久一区二区三区| 欧美久久综合性欧美| 久久这里只精品国产99热| 久久精品九九亚洲精品天堂| 人人狠狠综合久久亚洲婷婷| 久久久久中文字幕| 狠狠精品久久久无码中文字幕| 久久国产精品二国产精品| 久久免费大片| 亚洲精品无码成人片久久|