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

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


            思路:
            這題看上去挺唬人,提交的人也不多,實際上都是水題來的。
            1. 對于同一種字母,求出它出現位置的最左邊、最右邊、最上邊、最下邊。這就構成了一個矩形。
            2. 對于在x軸上投影重合的一系列矩形,他們必定處在同一個方格內。給這些方格編號。
            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 糯米 閱讀(532) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            久久五月精品中文字幕| 久久久无码人妻精品无码| 久久99亚洲综合精品首页| 久久无码人妻精品一区二区三区| 亚洲国产精品嫩草影院久久| 久久精品中文无码资源站| 国产成人香蕉久久久久| 人妻精品久久无码专区精东影业| 久久精品国产亚洲综合色| 久久亚洲AV无码精品色午夜麻豆| 成人国内精品久久久久一区| 亚洲国产婷婷香蕉久久久久久| 一本久久a久久精品vr综合| a级毛片无码兔费真人久久| 精品久久人人爽天天玩人人妻 | 精品久久久久久无码人妻热| 2019久久久高清456| 久久久久久青草大香综合精品| 久久精品国产亚洲AV无码麻豆| 久久久久亚洲AV无码专区桃色| 精品久久久久香蕉网| 亚洲中文字幕无码久久2017| 欧美久久综合九色综合| 91精品国产91久久久久久| AV无码久久久久不卡蜜桃| 无码人妻少妇久久中文字幕蜜桃| 亚洲精品无码久久不卡| 欧美亚洲日本久久精品| 久久国产精品视频| 久久精品国内一区二区三区 | 久久综合给合久久国产免费 | 亚洲AV无码久久精品蜜桃| 亚洲人成电影网站久久| 一级做a爰片久久毛片免费陪| 久久免费香蕉视频| 久久影视综合亚洲| 久久天天婷婷五月俺也去| 久久这里都是精品| 久久人做人爽一区二区三区| 久久久久精品国产亚洲AV无码| 99久久免费国产精品特黄|