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

            糯米

            TI DaVinci, gstreamer, ffmpeg
            隨筆 - 167, 文章 - 0, 評論 - 47, 引用 - 0
            數據加載中……

            POJ 2187 Beauty Contest 凸包直徑

            題目大意:
            給一堆點,求直線距離最遠的兩個點。

            思路:
            就是求“凸多邊形的直徑”。google一下,很多結果的啦。
            首先要求出凸包,然后用一個比較牛逼的算法貌似可以在O(N)時間內求出凸包直徑。
            但是那算法太復雜啦,看了半天都看不懂,所以就枚舉凸包每兩個點之間的距離了。
            還是能200+ms過,因為凸包求出來以后,N就大大減小了。

            #include <stdio.h>
            #include 
            <stdlib.h>

            struct point {
                
            short x, y;
            }
            ;
            struct point points[50024], *convex[50024];
            int points_cnt, convex_cnt;

            __inline 
            void swap(struct point *a, struct point *b)
            {
                
            struct point t = *a;
                
            *= *b;
                
            *= t;
            }


            __inline 
            int cmp(struct point *p1, struct point *p2)
            {
                
            int a, b, c, d, r;
                
                a 
            = p1->- points[0].y;
                b 
            = p1->- points[0].x;
                c 
            = p2->- points[0].y;
                d 
            = p2->- points[0].x;
                r 
            = a*- b*c;
                
            if (!r) {
                    
            if (b)
                        
            return b - d;
                    
            return a - c;
                }

                
            return r;
            }


            __inline 
            int turn_left(struct point *p1, struct point *p2, struct point *p3)
            {
                
            return    (int)p1->x*p2->- (int)p1->x*p3->- (int)p2->x*p1->+ 
                        (
            int)p3->x*p1->+ (int)p2->x*p3->- (int)p3->x*p2->y
                        
            >= 0;
            }


            void qs(struct point *arr, int len)
            {
                
            int l, r, p;
                
                
            if (len < 2)
                    
            return ;

                l 
            = 0;
                p 
            = len - 1;
                r 
            = len - 2;
                
            while (1{
                    
            while (l < p && cmp(&arr[l], &arr[p]) < 0)
                        l
            ++;
                    
            while (r >= 0 && cmp(&arr[r], &arr[p]) >= 0)
                        r
            --;
                    
            if (l > r)
                        
            break;
                    swap(
            &arr[l], &arr[r]);
                }

                swap(
            &arr[l], &arr[p]);

                qs(arr, l);
                qs(arr 
            + l + 1, len - l - 1);
            }


            int main()
            {
                
            int i, j, x, y, left, down, min_idx, max_val, val;

                freopen(
            "e:\\test\\in.txt""r", stdin);

                scanf(
            "%d"&points_cnt);
                left 
            = down = 0x7fffffff;
                
            for (i = 0; i < points_cnt; i++{
                    scanf(
            "%d%d"&x, &y);
                    points[i].x 
            = x;
                    points[i].y 
            = y;
                    
            if (x < left || (x == left) && y < down) {
                        left 
            = x;
                        down 
            = y;
                        min_idx 
            = i;
                    }

                }

                swap(
            &points[0], &points[min_idx]);
                qs(points 
            + 1, points_cnt - 1);

                convex_cnt 
            = 0;
                convex[convex_cnt
            ++= &points[0];
                convex[convex_cnt
            ++= &points[1];
                
            for (i = 2; i < points_cnt; i++{
                    
            while (convex_cnt >= 2 && 
                           
            !turn_left(convex[convex_cnt - 2], 
                                     convex[convex_cnt 
            - 1],
                                     
            &points[i]))
                    
            {
                          convex_cnt
            --;
                    }

                    convex[convex_cnt
            ++= &points[i];
                }


                max_val 
            = 0;
                
            for (i = 0; i < convex_cnt - 1; i++{
                    
            for (j = i + 1; j < convex_cnt; j++{
                        x 
            = convex[i]->- convex[j]->x;
                        y 
            = convex[i]->- convex[j]->y;
                        val 
            = x*+ y*y;
                        
            if (val > max_val)
                            max_val 
            = val;
                    }

                }

                printf(
            "%d\n", max_val);

                
            return 0;
            }

            posted on 2010-02-16 14:05 糯米 閱讀(449) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            欧美一级久久久久久久大片| 久久综合久久综合亚洲| 久久精品中文字幕无码绿巨人| 欧美一区二区三区久久综合| 国产精品美女久久久久| 怡红院日本一道日本久久 | 欧洲成人午夜精品无码区久久| 亚洲精品蜜桃久久久久久| 91精品国产91久久久久久| 久久人人爽人人爽AV片| 国产产无码乱码精品久久鸭| 久久国产成人亚洲精品影院| 久久久久亚洲Av无码专| 久久亚洲电影| 久久e热在这里只有国产中文精品99| 波多野结衣AV无码久久一区| 精品久久久久久国产牛牛app| 久久婷婷五月综合97色| 久久精品国产亚洲AV忘忧草18| 国产农村妇女毛片精品久久| 国产精品99久久99久久久| 色狠狠久久综合网| 亚洲精品国精品久久99热| 精品一久久香蕉国产线看播放 | 精品国产VA久久久久久久冰| 2021久久精品免费观看| 日韩欧美亚洲综合久久影院Ds| 青青青青久久精品国产h| 久久精品中文字幕无码绿巨人| 久久国内免费视频| 怡红院日本一道日本久久 | 欧美久久天天综合香蕉伊| 秋霞久久国产精品电影院| 国产精品久久久久…| 久久一日本道色综合久久| 亚洲第一极品精品无码久久| 狠狠精品久久久无码中文字幕| 一本大道久久东京热无码AV | 狠狠色丁香久久综合五月| 久久国产热精品波多野结衣AV| 久久精品国产亚洲av水果派|