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

            導航

            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久久精品国产Sm最大网站| 精品久久久久久无码不卡| 国产午夜精品久久久久免费视| 久久久国产精品亚洲一区| 99久久无码一区人妻a黑| 久久精品二区| 韩国免费A级毛片久久| 久久久99精品成人片中文字幕 | 99久久99久久精品免费看蜜桃| 99精品久久久久中文字幕| 久久99精品久久久久久9蜜桃| 久久久久久久波多野结衣高潮| 精品国产福利久久久| 久久久久久精品成人免费图片| 久久久久国产精品| 亚洲综合精品香蕉久久网| 久久AⅤ人妻少妇嫩草影院| 久久99精品久久只有精品| 色婷婷狠狠久久综合五月| 一本大道加勒比久久综合| 久久夜色精品国产欧美乱| 久久精品极品盛宴观看| 精品视频久久久久| 色噜噜狠狠先锋影音久久| 麻豆AV一区二区三区久久| 日本久久中文字幕| 久久精品国产精品亚洲艾草网美妙| 精品久久久久久中文字幕| 97久久国产露脸精品国产| 无码任你躁久久久久久久| 99久久国产综合精品成人影院| av无码久久久久不卡免费网站| 欧洲人妻丰满av无码久久不卡| 久久亚洲AV无码精品色午夜| 香蕉久久久久久狠狠色| 色8激情欧美成人久久综合电| 久久久久久国产精品无码下载| 精品国产乱码久久久久久浪潮| 久久精品一区二区国产| 91超碰碰碰碰久久久久久综合| 99热热久久这里只有精品68|