• <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>

            A Za, A Za, Fighting...

            堅(jiān)信:勤能補(bǔ)拙

            PKU 1089 Intervals

            問題:
            http://poj.org/problem?id=1089

            思路:
            根據(jù)interval的begin升序排列,然后對(duì)于interval A, B只存在三種情況:
            A包含B、A與B相交、A與B分離

            代碼:
             1 #include<stdio.h>
             2 #include<stdlib.h>
             3 #include<string.h>
             4 #define MAX_LEN 50001
             5 struct Interval {
             6     int begin, end;
             7 }itvs[MAX_LEN], target[MAX_LEN];
             8 int N, total;
             9 
            10 int
            11 compare(const void *arg1, const void *arg2)
            12 {
            13     struct Interval *= (struct Interval *)arg1;
            14     struct Interval *= (struct Interval *)arg2;
            15     if(a->begin == b->begin)
            16         return a->end - b->end;
            17     return a->begin - b->begin;
            18 }
            19 
            20 void
            21 init()
            22 {
            23     int i;
            24     for(i=0; i<N; i++)
            25         scanf("%d %d"&itvs[i].begin, &itvs[i].end);
            26     qsort(itvs, N, sizeof(struct Interval), compare);
            27     total = 0;
            28 }
            29 
            30 void
            31 solve()
            32 {
            33     int i;
            34     struct Interval cur = itvs[0];
            35     for(i=1; i<N; i++) {
            36         if(itvs[i].begin > cur.end) {
            37             target[total++= cur;
            38             cur = itvs[i];
            39         } else {
            40             if(itvs[i].end > cur.end)
            41                 cur.end = itvs[i].end;
            42         }
            43     }
            44     target[total++= cur;
            45 }
            46 
            47 void
            48 output()
            49 {
            50     int i;
            51     for(i=0; i<total; i++)
            52         printf("%d %d\n", target[i].begin, target[i].end);
            53 }
            54 
            55 int
            56 main(int argc, char **argv)
            57 {
            58     while(scanf("%d"&N) != EOF) {
            59         init();
            60         solve();
            61         output();
            62     }
            63 }

            posted on 2010-10-17 19:35 simplyzhao 閱讀(204) 評(píng)論(0)  編輯 收藏 引用 所屬分類: A_排序

            導(dǎo)航

            <2011年7月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            奇米影视7777久久精品| 久久97久久97精品免视看秋霞| 99久久精品国产一区二区| 久久午夜伦鲁片免费无码| 欧美伊人久久大香线蕉综合| 久久久精品国产亚洲成人满18免费网站| 99久久精品国产麻豆| 久久香蕉国产线看观看99| 99久久国产热无码精品免费| 久久久无码人妻精品无码| 久久婷婷五月综合97色一本一本| 久久天天躁狠狠躁夜夜躁2O2O| 国内精品伊人久久久久777| 精产国品久久一二三产区区别| 国内精品伊人久久久影院| 国产精品亚洲综合久久| 日本强好片久久久久久AAA| 久久亚洲中文字幕精品有坂深雪 | 久久精品国产亚洲一区二区| 99久久久精品免费观看国产| 嫩草影院久久国产精品| 久久久久九国产精品| 久久久久99这里有精品10| 亚洲国产精品无码久久一区二区| 久久精品国产亚洲av影院| 亚洲伊人久久大香线蕉苏妲己| 久久本道久久综合伊人| 亚洲日韩中文无码久久| 18岁日韩内射颜射午夜久久成人| 久久高清一级毛片| 久久综合狠狠综合久久| 久久精品国产亚洲7777| 97精品依人久久久大香线蕉97| 国产精品久久免费| 香蕉久久夜色精品国产2020| av午夜福利一片免费看久久| 亚洲欧洲久久久精品| 国产综合久久久久| 老男人久久青草av高清| 秋霞久久国产精品电影院| 五月丁香综合激情六月久久|