• <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
            久久只有这精品99| 香蕉99久久国产综合精品宅男自| 亚洲国产美女精品久久久久∴| 亚洲色大成网站WWW久久九九| 久久精品中文字幕久久| 日日狠狠久久偷偷色综合免费| 久久中文骚妇内射| 久久国产一片免费观看| 亚洲欧美日韩中文久久| 久久精品视频91| 久久久精品国产sm调教网站 | 久久亚洲国产成人精品无码区| 18禁黄久久久AAA片| 国产精品美女久久久久AV福利| 国内精品久久国产| 国产成人综合久久久久久| 久久人人爽爽爽人久久久| 亚洲国产成人久久综合野外| 色综合久久最新中文字幕| 久久亚洲精品中文字幕| 中文字幕精品无码久久久久久3D日动漫| 97久久综合精品久久久综合 | 国产精品久久亚洲不卡动漫| 综合久久精品色| 久久精品国产只有精品66| 中文字幕亚洲综合久久| 国产亚洲精久久久久久无码| 伊人久久大香线蕉av一区| 伊人精品久久久久7777| 麻豆国内精品久久久久久| 国产精品九九久久免费视频 | 国内精品久久久久久久久电影网| 日韩精品久久久肉伦网站| 一本久久知道综合久久| 久久精品国产精品亚洲精品| 久久久久精品国产亚洲AV无码| 亚洲欧美国产精品专区久久| 亚洲欧洲精品成人久久奇米网| 一本大道久久香蕉成人网| 久久人做人爽一区二区三区| 亚洲AV日韩精品久久久久久|