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

            C小加

            厚德 博學(xué) 求真 至善 The bright moon and breeze
            posts - 145, comments - 195, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            Ural 1019. Line Painting 解題報告

            Posted on 2012-01-18 00:42 C小加 閱讀(1948) 評論(6)  編輯 收藏 引用 所屬分類: 解題報告
            離散化+樸素算法。當(dāng)然用線段樹也可以過,我主要是想練習(xí)一下離散化,所以直接樸素了(更新5000次以內(nèi),離散化后的長度1萬以內(nèi))。誰會想到半夜這個時候我居然在切題。第二次寫離散化,可能與第一次隔的時間有點(diǎn)長,寫的一塌糊涂。大家眼中的水題被我搞得人不像人,鬼不像鬼。好失落。

            #include<iostream>
            #include<cstdio>
            #include<algorithm>
            #include<cstring>
            using namespace std;
            inline int L(int r){return r<<1;}
            inline int R(int r){return ((r<<1)+1);}

            const int MAXM=5003;
            typedef struct
            {
                int zy,value;
            }line;
            line node[MAXM*2];
            int post[MAXM][2];
            char col[MAXM][2];
            int l[MAXM*2];
            int zz[MAXM*2];

            void ranse(int b,int e,int c)
            {
                for(int i=b;i<e;i++)
                {
                    l[i]=c;
                }
            }
            bool cmp(line l1,line l2)
            {
                return l1.value<l2.value;
            }

            int main()
            {
                int n;
                scanf("%d",&n);
                post[0][0]=0;
                post[0][1]=1000000000;
                col[0][0]='w';
                    node[L(0)].zy=-0-1;//左值為負(fù)
                    node[R(0)].zy=0+1;//右值為正
                    node[L(0)].value=post[0][0];//把左右界坐標(biāo)真值儲存在結(jié)構(gòu)體數(shù)組中
                    node[R(0)].value=post[0][1];

                for(int i=1;i<=n;i++)
                {
                    scanf("%d %d %s",&post[i][0],&post[i][1],col[i]);
                    //getchar();
                    node[L(i)].zy=-i-1;//左值為負(fù)
                    node[R(i)].zy=i+1;//右值為正
                    node[L(i)].value=post[i][0];//把左右界坐標(biāo)真值儲存在結(jié)構(gòu)體數(shù)組中
                    node[R(i)].value=post[i][1];
                }
                sort(node,node+(n+1)*2,cmp);//對所有坐標(biāo)進(jìn)行排序
                int count=0,temp=node[0].value;//count為離散化后坐標(biāo)值。
                for(int i=0;i<2*(n+1);i++)
                {
                    if(node[i].value!=temp)//如果坐標(biāo)不同,則坐標(biāo)加1
                    {
                        count++;
                        temp=node[i].value;
                    }

                    if(node[i].zy<0) post[-node[i].zy-1][0]=count;//新post為離散化過后,左右界值
                    else post[node[i].zy-1][1]=count;
                    zz[count]=node[i].value;
                }
                memset(l,0,sizeof(l));
                l[count]=1;
                for(int i=0;i<=n;i++)
                {
                    if(col[i][0]=='w') ranse(post[i][0],post[i][1],0);
                    else ranse(post[i][0],post[i][1],1);
                }
                int sum=0;
                int ans=0;
                int z,y,ansz,ansy;
                for(int i=0;i<=count;i++)
                {
                    if(l[i]==0)
                    {
                        if(sum==0) z=zz[i];
                         sum++;
                    }
                    else
                    {

                        if(sum!=0)
                        {
                            y=zz[i]-z;
                            if(y>ans)
                            {
                                ans=y;
                                ansz=z;
                                ansy=zz[i];
                            }
                            sum=0;
                        }

                    }
                }
                printf("%d %d\n",ansz,ansy);
                return 0;
            }

            Feedback

            # re: Ural 1019. Line Painting 解題報告[未登錄]  回復(fù)  更多評論   

            2012-01-18 09:32 by 春秋十二月
            有潛力,思維能力不錯,但覺得你的程序還缺乏工業(yè)強(qiáng)度,繼續(xù)努力

            # re: Ural 1019. Line Painting 解題報告  回復(fù)  更多評論   

            2012-01-18 21:45 by C小加
            謝謝,我會繼續(xù)努力的。還沒見過工業(yè)代碼。@春秋十二月

            # re: Ural 1019. Line Painting 解題報告  回復(fù)  更多評論   

            2012-05-17 17:42 by PaceLeola
            Some time before, I needed to buy a house for my organization but I did not have enough cash and could not order something. Thank goodness my sister proposed to try to take the <a href="http://goodfinance-blog.com">loan</a> from trustworthy bank. Therefore, I did so and was satisfied with my financial loan.

            # re: Ural 1019. Line Painting 解題報告  回復(fù)  更多評論   

            2013-04-22 21:06 by up here
            If you are in a rush and have no clue how to gain some spare time so as to generate first-rate resume, contact companies that propose to buy CV.
            18岁日韩内射颜射午夜久久成人 | 91久久九九无码成人网站| 久久久久久久久无码精品亚洲日韩 | 国产精品丝袜久久久久久不卡 | 亚洲精品乱码久久久久久中文字幕| 无码国内精品久久人妻蜜桃| 久久se精品一区二区| 久久性生大片免费观看性| 亚洲第一极品精品无码久久| 欧美777精品久久久久网| 2021国内精品久久久久久影院| 久久久久久亚洲Av无码精品专口| 日批日出水久久亚洲精品tv| 久久久久久久人妻无码中文字幕爆| 久久精品国产72国产精福利| 99久久国产综合精品麻豆| 狠狠色丁香久久婷婷综合_中| 久久综合九色综合精品| 久久久久人妻一区精品色| 午夜精品久久久内射近拍高清 | 久久99国产精品成人欧美| 久久精品夜夜夜夜夜久久| 久久午夜无码鲁丝片秋霞| 狠狠色伊人久久精品综合网| 久久久久国产精品熟女影院| 99久久免费国产精品特黄| 久久久无码精品亚洲日韩软件| 久久99久久99小草精品免视看| 精品久久久中文字幕人妻 | 久久91这里精品国产2020| 国产精品禁18久久久夂久| 亚洲精品乱码久久久久久蜜桃不卡 | 精品水蜜桃久久久久久久| 91精品国产综合久久香蕉| 国产91久久精品一区二区| 久久精品国产第一区二区三区| 亚洲人成无码网站久久99热国产| 久久综合九色综合久99| 三级片免费观看久久| 久久久一本精品99久久精品88| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 |