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

            久久这里只有精品视频99| 久久久久国产精品嫩草影院| 亚洲国产天堂久久久久久| 亚洲人成网亚洲欧洲无码久久| 久久久国产亚洲精品| 好久久免费视频高清| 久久天天躁狠狠躁夜夜不卡 | 99久久精品国产一区二区三区| 亚洲精品乱码久久久久久不卡| 久久夜色精品国产亚洲| 久久精品国产福利国产琪琪| 欧美成a人片免费看久久| 性色欲网站人妻丰满中文久久不卡| 久久ww精品w免费人成| 伊人久久亚洲综合影院| 国产成人精品久久一区二区三区| 狠狠色狠狠色综合久久| 国产2021久久精品| 99久久夜色精品国产网站| 亚洲国产天堂久久综合| 91精品国产综合久久婷婷| 99久久做夜夜爱天天做精品| 婷婷综合久久狠狠色99h| 69久久精品无码一区二区| 亚洲午夜精品久久久久久浪潮 | 久久婷婷五月综合色奶水99啪 | 久久精品国产精品亚洲精品| 无夜精品久久久久久| 久久这里的只有是精品23| 91久久成人免费| 国产一级持黄大片99久久| 色综合久久综合中文综合网| 香蕉99久久国产综合精品宅男自| 欧美精品一本久久男人的天堂| 久久亚洲AV成人无码国产| 一本一本久久A久久综合精品 | 久久这里只有精品久久| 久久久精品人妻一区二区三区蜜桃 | 亚洲精品无码久久一线| 久久精品中文字幕大胸| 中文字幕久久精品|