• <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>
            隨筆-21  評(píng)論-10  文章-21  trackbacks-0
             1 #include<iostream>
             2 #include<cmath>
             3 #include<vector>
             4 #include<algorithm>
             5 #include<cstdio>
             6 using namespace std;
             7 const int maxn  = 60000;
             8 
             9 struct Point {              // 二維點(diǎn)或矢量
            10     int x, y;
            11     Point() {}
            12     Point(int x0, int y0): x(x0), y(y0) {}
            13 };
            14 
            15 
            16 struct Polygon{
            17     Point p[maxn];
            18     int n;
            19 };
            20 
            21 //二維矢量運(yùn)算
            22 bool operator==(Point p1, Point p2)
            23 {
            24     return ( p1.x - p2.x==0 &&  p1.y - p2.y==0);
            25 }
            26 bool operator!=(Point p1, Point p2)
            27 {
            28     return ( p1.x - p2.x != 0 ||  p1.y - p2.y != 0);
            29 }
            30 bool operator<(Point p1, Point p2)
            31 {
            32     return p1.x < p2.x || p1.x - p2.x==0 &&  p1.y < p2.y;
            33 }
            34 Point operator+(Point p1, Point p2)
            35 {
            36     return Point(p1.x + p2.x, p1.y + p2.y);
            37 }
            38 Point operator-(Point p1, Point p2)
            39 {
            40     return Point(p1.x - p2.x, p1.y - p2.y);
            41 }
            42 int operator*(Point p1, Point p2) // 計(jì)算叉乘 p1 × p2
            43 {
            44     return (p1.x * p2.y - p2.x * p1.y);
            45 }
            46 int operator&(Point p1, Point p2) { // 計(jì)算點(diǎn)積 p1·p2
            47     return (p1.x * p2.x + p1.y * p2.y);
            48 }
            49 
            50 
            51 //Graham 凸包
            52 
            53 Polygon Convex_Hull( Point FP[], int fn)
            54 {
            55     int i, k;
            56     Polygon res;
            57     sort(FP, FP+fn );
            58     res.n = 0;
            59     for(i = 0; i < fn; ++i )
            60     {
            61         while(res.n>=2 &&  ( res.p[res.n-1- res.p[res.n-2] ) *( FP[i] - res.p[res.n-2] ) <= 0) res.n--;
            62         res.p[res.n++= FP[i];
            63     }
            64     k = res.n;
            65     for(i = fn-2; i>=0; i--)
            66     {
            67         while(res.n > k && ( res.p[res.n-1- res.p[res.n-2]) * ( FP[i] - res.p[res.n-2] ) <= 0 ) res.n--;
            68         res.p[res.n++= FP[i];
            69     }
            70     res.n--;
            71     return res;
            72 }
            73 
            74 Polygon ans;
            75 Point FP[maxn];
            76 int FN;
            77 
            78 int main(){
            79     int i, j;
            80     int dis, best = -1;
            81     scanf("%d",&FN);
            82     for(i = 0; i < FN; i++)
            83         scanf("%d%d",&FP[i].x , &FP[i].y);
            84     ans = Convex_Hull( FP, FN);
            85     for(i = 0; i < ans.n; i++)
            86         for(j = 0; j < ans.n; j++)
            87         {
            88             dis = (ans.p[i].x - ans.p[j].x)*(ans.p[i].x - ans.p[j].x)+(ans.p[i].y - ans.p[j].y)*(ans.p[i].y - ans.p[j].y);
            89             if(dis > best)best = dis;
            90         }
            91     printf("%d\n",best);
            92 }


            能使用整點(diǎn)函數(shù)的盡量使用整點(diǎn)函數(shù),避免精度問(wèn)題

            posted on 2009-09-01 08:48 wangzhihao 閱讀(174) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): geometry
            精产国品久久一二三产区区别| 少妇无套内谢久久久久| 久久99精品久久久久久动态图| 日产精品久久久一区二区| 国产精品久久久久国产A级| 99热精品久久只有精品| 午夜福利91久久福利| 99国产欧美精品久久久蜜芽| 久久综合亚洲色HEZYO国产| 人妻少妇久久中文字幕| 久久本道综合久久伊人| 久久人人爽人人爽人人片AV不| 99久久777色| 三级三级久久三级久久| 91精品日韩人妻无码久久不卡 | 亚洲中文字幕无码久久综合网| 久久综合综合久久狠狠狠97色88| 一本色道久久88精品综合| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 久久99国产精品尤物| 中文字幕无码久久人妻| 亚洲国产精品久久| 91精品国产综合久久精品| 7777精品伊人久久久大香线蕉| 国产成人无码精品久久久久免费| 久久精品亚洲一区二区三区浴池| 欧美亚洲国产精品久久| 久久精品成人欧美大片 | 青青草国产精品久久| 一本大道久久香蕉成人网| 欧美精品一本久久男人的天堂| 无码人妻久久一区二区三区免费丨 | 九九久久精品无码专区| 国产精品日韩欧美久久综合| 久久99国产综合精品免费| 中文字幕人妻色偷偷久久| 狠狠色综合网站久久久久久久高清| 开心久久婷婷综合中文字幕| 久久青青国产| 国内精品综合久久久40p| 色欲久久久天天天综合网|