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

            堅信:勤能補拙

            PKU 1089 Intervals

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

            思路:
            根據interval的begin升序排列,然后對于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 閱讀(203) 評論(0)  編輯 收藏 引用 所屬分類: A_排序

            導航

            <2010年9月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            色婷婷综合久久久久中文 | 久久香综合精品久久伊人| 久久免费精品视频| 午夜天堂av天堂久久久| 一级a性色生活片久久无少妇一级婬片免费放 | 久久人人爽人人爽人人AV东京热| 色欲综合久久躁天天躁| 国产精品午夜久久| 国产呻吟久久久久久久92| 青青青青久久精品国产h| 国产精品久久久久久| 国产成人久久AV免费| 久久国产乱子伦免费精品| 国产精品久久久久影院嫩草| 久久精品亚洲日本波多野结衣 | 一本久道久久综合狠狠躁AV| 欧美久久一级内射wwwwww.| 久久久久国产精品嫩草影院 | 亚洲国产成人久久综合一区77| 久久亚洲电影| 久久天天躁狠狠躁夜夜不卡| 久久亚洲AV无码精品色午夜麻豆| 亚洲精品无码久久久久久| 蜜臀av性久久久久蜜臀aⅴ| 精品精品国产自在久久高清| 四虎国产永久免费久久| 久久久久久国产a免费观看不卡| 久久免费99精品国产自在现线| 久久久久久免费视频| 日韩精品久久无码人妻中文字幕| 久久国产色AV免费观看| 国产精品熟女福利久久AV| 色婷婷久久久SWAG精品| 久久精品水蜜桃av综合天堂| 丁香久久婷婷国产午夜视频| 超级碰碰碰碰97久久久久| 狠狠色丁香久久婷婷综合五月| 久久精品一区二区三区中文字幕| 99精品久久久久久久婷婷| 国产成人久久精品激情| 欧美日韩精品久久久久|