• <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>
            數(shù)據(jù)加載中……

            URAL 1019 A line painting

            A Line painting

            Time Limit: 2.0 second
            Memory Limit: 16 MB
            The segment of numerical axis from 0 to 109 is painted into white color. After that some parts of this segment are painted into black, then some into white again and so on. In total there have been made N re-paintings (1 ≤ N ≤ 5000). You are to write a program that finds the longest white open interval after this sequence of re-paintings.

            Input

            The first line of input contains the only number N. Next N lines contain information about re-paintings. Each of these lines has a form:
            ai bi ci
            where ai and bi are integers, ci is symbol 'b' or 'w', ai, bi, ci are separated by spaces.
            This triple of parameters represents repainting of segment from ai to bi into color ci ('w' — white, 'b' — black). You may assume that 0 < ai < bi < 109.

            Output

            Output should contain two numbers x and y (x < y) divided by space(s). These numbers should define the longest white open interval. If there are more than one such an interval output should contain the one with the smallest x.

            Sample

            input output
            4
            1 999999997 b
            40 300 w
            300 634 w
            43 47 b
            47 634                                                        
            這個題目最直接的辦法是離散化,離散化了之后就好折騰了,因?yàn)椴僮髦噶詈苌?所以我選擇離散+樸素染色.
            復(fù)雜度上界為O(M*M),這里M表示離散化后得到的區(qū)間個數(shù).

             1 #include<iostream>
             2 #include<algorithm>
             3 using namespace std;
             4 const int MAXN=10005;
             5 const int MAXL=1000000000;
             6 struct re
             7 {
             8   int a,b;
             9   char c;
            10 }op[MAXN];
            11 
            12 int n,p=0,que[MAXN];
            13 bool color[MAXN<<1];
            14 
            15 /* 二分查找 */
            16 int find(int num)
            17 {
            18   int l=0,r=p+1,mid;
            19   while (r-l>1)
            20     {
            21       mid=(l+r) >> 1;
            22       (que[mid]<=num)? l=mid : r=mid;
            23       if (que[l]==num) return l;
            24     }
            25   return l;
            26 }
            27 
            28 void disp(re& op)
            29 {
            30   /* 區(qū)間由1開始數(shù),而不是由0開始 */
            31   op.a=find(op.a)+1;
            32   op.b=find(op.b);
            33 }
            34 
            35 void mark(int l,int r,char c)
            36 {
            37   for (int i=l;i<=r;++i) color[i]=(c=='b');
            38 }
            39 
            40 int main()
            41 {
            42  // freopen("data.in","r",stdin);
            43  // freopen("data.out","w",stdout);
            44   cin >> n;
            45   for (int i=0;i<n;++i)
            46     {
            47       cin >> op[i].a >> op[i].b >> op[i].c;
            48       que[++p]=op[i].a;
            49       que[++p]=op[i].b;
            50     }
            51   que[++p]=MAXL;
            52   /* 刪除重復(fù)出現(xiàn)的數(shù)字 */
            53   int rp=0;
            54   for (int i=1;i<=p;++i)
            55     if (que[rp]!=que[i]) que[++rp]=que[i];
            56   p=rp;
            57   /* 排序,便于定位和離散化 */
            58   sort(que,que+p+1);
            59   que[p+1]=MAXL+1;
            60   /* 對操作進(jìn)行離散處理 */
            61   for (int i=0;i<n;++i) disp(op[i]);
            62   /* 處理操作序列 */
            63   memset(color,0,sizeof(color));
            64   for (int i=0;i<n;++i) mark(op[i].a,op[i].b,op[i].c);
            65   int t=1,a,b,mlen=0;
            66   for (int i=2;i<=p+1;++i)
            67     if (color[i]!=color[t] || i>p)
            68       { 
            69     if ((!color[t]) && (que[i-1]-que[t-1]>mlen)) { a=que[t-1];b=que[i-1];mlen=que[i-1]-que[t-1];}
            70     t=i;
            71       }
            72   cout << a << ' ' << b << endl;
            73   //system("pause");
            74   return 0;
            75 }
            76 
            個別目標(biāo)遠(yuǎn)大的同學(xué)可能并不僅僅是想解決這個題目,這時候建議你使用離散化+線段樹,復(fù)雜度會大大地降低

            posted on 2009-07-20 15:00 Chen Jiecao 閱讀(419) 評論(0)  編輯 收藏 引用 所屬分類: URAL

            久久亚洲高清综合| 国产高潮国产高潮久久久91| 久久久久久国产精品美女| 久久久久人妻一区精品果冻| 性高湖久久久久久久久AAAAA| 久久人搡人人玩人妻精品首页| 久久无码一区二区三区少妇| 亚洲午夜精品久久久久久app| 一级做a爰片久久毛片看看| 99久久这里只精品国产免费| 欧美黑人又粗又大久久久| 狠狠色丁香婷婷久久综合不卡| 国产精品成人无码久久久久久| 2021国产精品午夜久久| 国产精品一久久香蕉产线看| 欧美久久久久久精选9999| 97精品伊人久久久大香线蕉| 99热精品久久只有精品| 免费精品久久天干天干| 国产精品伦理久久久久久| 亚洲精品无码久久一线| a级毛片无码兔费真人久久| 久久久久久精品无码人妻| 久久精品国产影库免费看| 久久精品卫校国产小美女| 国产精品免费看久久久香蕉| 久久婷婷五月综合色高清| 久久99热这里只频精品6| 97久久精品人人做人人爽| 久久精品黄AA片一区二区三区| 女同久久| 久久久久97国产精华液好用吗| 国产精品9999久久久久| 一本一本久久A久久综合精品 | 久久精品国产亚洲AV蜜臀色欲 | 亚洲国产成人乱码精品女人久久久不卡| 亚洲狠狠婷婷综合久久蜜芽| 久久午夜夜伦鲁鲁片免费无码影视 | 看久久久久久a级毛片| 久久久久久久女国产乱让韩| 久久天天躁狠狠躁夜夜不卡 |