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

            The Fourth Dimension Space

            枯葉北風(fēng)寒,忽然年以殘,念往昔,語(yǔ)默心酸。二十光陰無(wú)一物,韶光賤,寐難安; 不畏形影單,道途阻且慢,哪曲折,如渡飛湍。斬浪劈波酬壯志,同把酒,共言歡! -如夢(mèng)令

            HDOJ 1007 Quoit Design 平面最近點(diǎn)對(duì)

            剛好課上學(xué)了平面最近點(diǎn)對(duì)的算法,回來實(shí)現(xiàn)以下,恩 ,分治的思想很重要。呵呵,又學(xué)會(huì)了一個(gè)算法。

            #include<iostream>
            #include
            <cstdio>
            #include
            <cmath>
            #include
            <algorithm>
            using namespace std;
            #define eps 1e-8

            const int maxn=200001;
            const double INF=999999999;

            typedef 
            struct point
            {
                
            double x,y;
                
            //int flag;
                point(){};  
            }
            point;
            point p[maxn];
            int n; 
            int cmp(double x,double y)
            {
                
            if(x==y)return 0;
                
            if(x>y)return 1;
                
            return -1
            }
                   

            bool cmp1(point a,point b)
            {
                
            if(a.x!=b.x)
                    
            return a.x<b.x;
                
            else
                    
            return a.y<b.y;
            }

            bool cmp2(int i,int j)
            {
                
            return cmp(p[i].y,p[j].y)<0;
            }

            double dist(point &a,point &b)
            {
                
            return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
            }



            int y[maxn],len;
            double cp(point p[],int l,int r)//求從l到r這些點(diǎn)的最近點(diǎn)對(duì)
            {
                
            int i,j;
                
            int mid=(l+r)>>1;
                
            double ret=INF;
                
            if(l>=r)
                    
            return ret;
                
            for(i=mid;i>=l&&!cmp(p[i].x,p[mid].x);i--);
                
            double t1=cp(p,l,i);
                
            for(i=mid;i<=r&&!cmp(p[i].x,p[mid].x);i++);
                
            double t2=cp(p,i,r);
                
            if(t1<t2)
                    ret
            =t1;
                
            else ret=t2;

                len
            =0;
                
            for(i=l;i<=r;i++)
                
            {
                    
            if(fabs(p[i].x-p[mid].x)<ret)
                        y[
            ++len]=i;
                }


                sort(y
            +1,y+len+1,cmp2);

                
            for(i=1;i<=len;i++)
                
            {
                    
            int cnt=1;
                    
            for(j=i+1;j<=len&&cnt<=7;j++)
                    
            {
                        ret
            =min(ret,dist(p[y[i]],p[y[j]])); 
                        cnt
            ++;
                    }

                }

                
            return ret;
            }


            bool check(int n)
            {
                
            int i;
                
            for(i=2;i<=n;i++)
                
            {
                    
            if(p[i].x==p[i-1].x&&p[i].y==p[i-1].y)
                        
            return true;
                }

                
            return false;
            }




            int main()
            {

                
            int n;
                
            while(scanf("%d",&n)!=EOF)
                
            {    
                    
            if(n==0)
                        
            break;

                    
            int i;
                    
            for(i=1;i<=n;i++)
                        scanf(
            "%lf%lf",&p[i].x,&p[i].y);
                    sort(p
            +1,p+n+1,cmp1);
                    
            if(check(n))
                    
            {
                        printf(
            "0.00\n");
                        
            continue;
                    }

                    
            double ans=cp(p,1,n)/2;
                    printf(
            "%.2lf\n",ans);

                }

                
            return 0;    

            }












             

            posted on 2010-05-20 20:13 abilitytao 閱讀(2248) 評(píng)論(4)  編輯 收藏 引用

            評(píng)論

            # re: HDOJ 1007 Quoit Design 平面最近點(diǎn)對(duì) 2010-05-21 00:43 矩陣操作

            遍歷比較距離時(shí)你根本就不需要進(jìn)行開平方這個(gè)多余的耗時(shí)操作
            哎。。。
              回復(fù)  更多評(píng)論   

            # re: HDOJ 1007 Quoit Design 平面最近點(diǎn)對(duì)[未登錄] 2010-05-21 01:17 abilitytao

            @矩陣操作
            有道理 :-) 多謝提醒  回復(fù)  更多評(píng)論   

            # re: HDOJ 1007 Quoit Design 平面最近點(diǎn)對(duì) 2010-05-21 17:54 <A href="mailto:wolf5x1016@gmail.com"

            delaunay triangualtion  回復(fù)  更多評(píng)論   

            # re: HDOJ 1007 Quoit Design 平面最近點(diǎn)對(duì)[未登錄] 2010-05-21 19:02 abilitytao

            @&lt;A href=&quot;mailto:wolf5x1016@gmail.com&quot;
            網(wǎng)頁(yè)爬蟲?  回復(fù)  更多評(píng)論   


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            欧美黑人又粗又大久久久| 亚洲精品乱码久久久久久蜜桃不卡| 色综合久久中文字幕无码| 亚洲精品无码久久久久| 久久精品国产亚洲精品2020| 99久久精品日本一区二区免费| 精品久久久久久亚洲| 久久久久国产一区二区| 囯产精品久久久久久久久蜜桃| 蜜臀av性久久久久蜜臀aⅴ麻豆| 秋霞久久国产精品电影院| 亚洲精品无码久久久久AV麻豆| 久久人人爽人人爽人人片AV不| 国产成人久久777777| 久久综合精品国产二区无码| 久久国产视屏| 丁香五月网久久综合| 一本一道久久综合狠狠老| 久久AⅤ人妻少妇嫩草影院| 久久A级毛片免费观看| 亚洲国产视频久久| 国产精品xxxx国产喷水亚洲国产精品无码久久一区| 国内精品久久久久久麻豆| 久久久久久九九99精品| 久久久精品久久久久影院| 精品久久人人妻人人做精品| 72种姿势欧美久久久久大黄蕉| 国产69精品久久久久观看软件| 精品人妻伦一二三区久久| 久久99精品综合国产首页| 偷偷做久久久久网站| 色综合久久88色综合天天 | 久久99精品国产一区二区三区| 久久99精品久久久久久动态图| 色综合久久夜色精品国产| 欧美伊人久久大香线蕉综合69| 国产精品久久久久乳精品爆| 99久久国产综合精品网成人影院| 精品久久久久久| 久久电影网一区| 国产精品热久久毛片|