• <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 糯米 閱讀(445) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            亚洲国产精久久久久久久| 亚洲精品久久久www| 国内精品伊人久久久久AV影院| 久久精品水蜜桃av综合天堂| 久久国产一区二区| 久久久久国产精品麻豆AR影院| 欧美亚洲国产精品久久高清| 国产产无码乱码精品久久鸭| 久久九九青青国产精品| 久久亚洲av无码精品浪潮| 亚洲精品乱码久久久久久按摩| 99re这里只有精品热久久| 日本免费一区二区久久人人澡| 一级做a爰片久久毛片免费陪| 久久国产精品二国产精品| 伊人色综合久久天天网| 天天爽天天爽天天片a久久网| 四虎影视久久久免费| 亚洲国产成人久久综合碰碰动漫3d | 久久婷婷五月综合成人D啪| 亚洲精品国产美女久久久| 亚洲午夜久久久| 女人香蕉久久**毛片精品| 日韩AV无码久久一区二区| 一本大道久久香蕉成人网| 久久青青草原国产精品免费| 少妇精品久久久一区二区三区| 亚洲欧洲精品成人久久曰影片 | 久久不见久久见免费影院www日本| 久久成人小视频| 亚洲午夜精品久久久久久app| 久久国产影院| 国产精品久久久天天影视香蕉| 久久综合丝袜日本网| 久久夜色tv网站| 久久99精品国产麻豆宅宅| 国产91久久综合| 久久艹国产| 无码八A片人妻少妇久久| 中文国产成人精品久久不卡| 18岁日韩内射颜射午夜久久成人|