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

            Uriel's Corner

            Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
            posts - 0, comments - 50, trackbacks - 0, articles - 594
                    原題地址:http://www.cn210.com/onlinejudge/problemshow.php?pro_id=181
                    期末考試的將近1個月時間都沒怎么做題,手很生,個人賽極其挫。。
                    這道是暑假集訓個人賽第二場最后一題,比賽當時沒人出。
                    題意很好懂就不重復了,那么大的數據,暴搜顯然不行。因為最后求有多少牛群和最大的牛群有多少只牛,很容易想到并查集。比賽當時我也就只想到了這么多,光用并查集不加別的優化肯定還是TLE的,所以就放棄了。
                    比賽完看了解題報告知道了要用AVL實現查找,刪除操作,因為數據結構講過,自己也看過,于是YY了很久,被左旋右旋繞暈了都沒出sample,今天問了大牛們才知道STL有個很神奇的set,查找之類的操作都可以O(lgn),于是又YY了很久總算AC了。。
                    參考的解題報告http://blog.imzzl.com/2010/05/406.html
             
                    我的丑陋的代碼:
            #include<set>
            #include
            <stdio.h>
            #include
            <string.h>
            #include
            <stdlib.h>
            #include
            <algorithm>
            using namespace std;

            struct point
            {
                
            int x,y,index;
                friend 
            bool operator<(const point &a,const point &b)
                
            {
                    
            if(a.y==b.y)return a.x<b.x;
                    
            return a.y<b.y;
                }

            }
            ;

            point p[
            100050];
            int cnt[100050],n,c,father[100050];

            set<point>SET;
            set<point>::iterator it1,it2;

            bool cmp(point a,point b)
            {
                
            return a.x<b.x;
            }


            int find(int x)      
            {
                
            if(father[x]==x)return x;
                
            else
                    
            return father[x]=find(father[x]);
            }


            void Union(int x,int y)     
            {
                
            int fx=find(x),fy=find(y);
                
            if(fx>fy)father[fx]=fy;
                
            else
                    father[fy]
            =fx;
            }


            void Sov()
            {
                
            int i,j,maxx,h,zzl;
                SET.insert(p[
            1]);
                h
            =1;
                
            for(i=2;i<=n;i++)
                
            {
                    
            while((p[i].x-p[h].x)>c)
                    
            {
                        SET.erase(p[h]);
                        h
            ++;
                    }

                    SET.insert(p[i]);
                    it1
            =it2=SET.find(p[i]);
                    it1
            --;
                    it2
            ++;
                    
            if(it1!=SET.end() && abs((it1)->y-p[i].y)<=c)
                    
            {
                        Union(i,it1
            ->index);
                    }

                    
            if(it2!=SET.end() && abs((it2)->y-p[i].y)<=c)
                    
            {
                        Union(it2
            ->index,i);
                    }

                }

                zzl
            =0;
                
            for(i=1;i<=n;i++)
                
            {
                    
            if(father[i]==i)zzl++;
                    cnt[find(i)]
            ++;
                }

                maxx
            =0;
                
            for(i=1;i<=n;i++)
                
            {
                    
            if(cnt[i]>maxx)maxx=cnt[i];
                }

                printf(
            "%d %d\n",zzl,maxx);
                
            return ;
            }


            int main()
            {
                
            int i,x,y;
                scanf(
            "%d %d",&n,&c);
                
            for(i=1;i<=n;i++)
                
            {
                    scanf(
            "%d %d",&x,&y);
                    p[i].x
            =x+y;p[i].y=x-y;
                    father[i]
            =i;
                    cnt[i]
            =0;
                }

                sort(p
            +1,p+n+1,cmp);
                
            for(i=1;i<=n;i++)p[i].index=i;
                Sov();
                
            return 0;
            }

            Feedback

            # re: USACO 2008 OPEN Gold & EOJ 181---Cow Neighborhoods 并查集+AVL樹  回復  更多評論   

            2010-07-17 07:09 by CrazyCow
            orz

            # re: USACO 2008 OPEN Gold & EOJ 181---Cow Neighborhoods 并查集+AVL樹  回復  更多評論   

            2010-07-18 17:51 by Uriel
            @CrazyCow

            ORZ
            久久伊人中文无码| 久久97精品久久久久久久不卡| 国产真实乱对白精彩久久| 久久久中文字幕日本| 婷婷久久久亚洲欧洲日产国码AV| 欧美综合天天夜夜久久| 久久露脸国产精品| 999久久久无码国产精品| 色诱久久av| 久久艹国产| 91精品国产91热久久久久福利| 97精品伊人久久久大香线蕉| 久久这里只有精品首页| 久久青青草原精品国产| 尹人香蕉久久99天天拍| 亚洲国产精品久久久久婷婷软件| 成人综合久久精品色婷婷| 青青草国产成人久久91网| 久久精品国产亚洲AV无码麻豆| 亚洲午夜精品久久久久久app| 99久久精品免费国产大片| 99国产欧美精品久久久蜜芽| 无码人妻久久一区二区三区| 婷婷国产天堂久久综合五月| 99久久精品国产一区二区| 狠色狠色狠狠色综合久久| 97久久精品无码一区二区天美| 影音先锋女人AV鲁色资源网久久 | 国产免费久久久久久无码| 国产精品一区二区久久不卡| 国产精品美女久久久网AV| 久久精品国产免费观看三人同眠| 久久亚洲春色中文字幕久久久| 久久久国产精品| 国产精品日韩深夜福利久久| 日韩精品国产自在久久现线拍| 99久久无色码中文字幕| 久久久久久狠狠丁香| 久久久精品波多野结衣| 青青热久久国产久精品| 久久无码中文字幕东京热|