• <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 閱讀(206) 評論(0)  編輯 收藏 引用 所屬分類: A_排序

            導航

            <2011年6月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久e热在这里只有国产中文精品99 | 久久影院久久香蕉国产线看观看| 国产精品一区二区久久精品| 97久久精品人妻人人搡人人玩| 一级做a爰片久久毛片16| 国产成人精品久久亚洲高清不卡| 人妻精品久久久久中文字幕| 色诱久久久久综合网ywww| 青青草原1769久久免费播放| 亚洲国产成人久久综合碰| 久久亚洲精品无码AV红樱桃| 久久久精品日本一区二区三区| 久久久精品人妻一区二区三区蜜桃| 久久ZYZ资源站无码中文动漫 | 色欲综合久久躁天天躁| 久久久亚洲欧洲日产国码aⅴ| 国产精品九九久久免费视频| 久久综合九色综合网站| 久久亚洲高清综合| 久久这里只精品国产99热| 久久久久亚洲AV无码观看| 久久精品?ⅴ无码中文字幕| 2021精品国产综合久久| 97久久国产露脸精品国产| 日本高清无卡码一区二区久久 | 久久精品国产精品亚洲艾草网美妙 | 久久久国产精品| 日本久久久久久中文字幕| 久久亚洲日韩精品一区二区三区| 欧美激情精品久久久久久| 精品久久久久国产免费| 亚洲国产精品人久久| 久久精品国产亚洲av水果派| 亚洲va中文字幕无码久久不卡| 亚洲欧美另类日本久久国产真实乱对白 | 99久久精品国产综合一区| 国内精品久久久久影院免费| 久久精品人人槡人妻人人玩AV| 思思久久精品在热线热| 久久久久久久综合狠狠综合| 中文字幕久久亚洲一区|