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

            我希望你是我獨家記憶

            一段永遠封存的記憶,隨風而去
            posts - 263, comments - 31, trackbacks - 0, articles - 3
               :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

            PKU——1113——(凸包)

            Posted on 2008-08-18 16:06 Hero 閱讀(402) 評論(0)  編輯 收藏 引用 所屬分類: 代碼如詩--ACM
            //1113 Accepted 452K 63MS G++ 4131B 
            //典型的凸包--注意xmult相同的時候按點從遠到進排序

            #include 
            <stdio.h>
            #include 
            <stdlib.h>
            #include 
            <string.h>
            #include 
            <ctype.h>
            #include 
            <math.h>
            #include 
            <iostream>
            using namespace std ;
            #define unllong unsigned long long 
            #define unint unsigned int
            #define printline  printf( "\n" ) 
            typedef 
            long long llong ;

            #define zero(x) (((x)>0?(x):-(x))<eps)

            const int Base=1000000000;//高精度
            const int Capacity=100;//高精度
            const double PI = 2.0*acos( 0.0 ) ;
            const double eps = 1e-8 ;
            const int INF = 1000000 ;

            const int size = 10010 ;

            struct POINT
            {
                
            double x ;
                
            double y ;
                
            double k ;
            };
            struct POINT point[size] ;

            int stack[size] ; 
            int top = 2 ;

            int inn; int inr ;
            double outarea ;
            double outlen ;

            double fdist( double x1, double y1, double x2, double y2 )
            {
                
            return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) ;
            }

            void input()
            {
                
            int leftdown = 0 ;
                
            forint i=0; i<inn; i++ ) {
                    scanf( 
            "%lf %lf"&point[i].x, &point[i].y ) ;
                    
            //if( miny>point[i].y || miny==point[i].y&&minx>point[i].x )
                    if( point[leftdown].y>point[i].y||zero(point[leftdown].y-point[i].y)&&point[leftdown].x>point[i].x )
                        leftdown 
            = i ;//找到最左下的點
                }
                
            double temp ;
                temp 
            = point[0].x ; point[0].x = point[leftdown].x ; point[leftdown].x = temp ;
                temp 
            = point[0].y ; point[0].y = point[leftdown].y ; point[leftdown].y = temp ;
                
            forint i=1; i<inn; i++ ) {
                    point[i].k 
            = atan2( point[i].y-point[0].y, point[i].x-point[0].x ) ;
                }
            //以點(minx, miny)計算極角
            }

            double xmult( POINT &p1, POINT &p2, POINT &p0 )
            {
            //計算叉乘--線段旋轉方向和對應的四邊形的面積--返回(p1-p0)*(p2-p0)叉積
                
            //if叉積為正--p0p1在p0p2的順時針方向; if(x==0)共線

                
            return (p1.x-p0.x)*(p2.y-p0.y) - (p2.x-p0.x)*(p1.y-p0.y) ;
            }

            int gramcmp1( const void *a, const void *b )
            {
                
            struct POINT *= (struct POINT *)a ;
                
            struct POINT *= (struct POINT *)b ;

                
            if( c->- d->> eps )    return 1 ;
                
            else if( c->- d->< -1*eps ) return -1 ;
                
            else//斜率相等距離近的點在先
                    return c->- d->> 0 ? 1 : -1 ;
            }

            int gramcmp( const void *a, const void *b )
            {
                
            struct POINT *= (struct POINT *)a ;
                
            struct POINT *= (struct POINT *)b ;

                
            double xmult_val = xmult( *c, *d, point[0] ) ;
                
            if( xmult_val > eps )    return -1 ;
                
            else if( xmult_val < -1*eps ) return 1 ;
                
            else return c->- d->> 0 ? 1 : -1 ;
                
            //else 
                
            //return fdist( c->x,c->y,point[0].x,point[0].y )>fdist(d->x,d->y,point[0].x,point[0].y)? -1:1 ;
            }

            void gramham()
            {
            //凸包的點存在于stack[]中
                qsort( point+1, inn-1sizeof(point[1]), gramcmp1 ) ;//極坐標排序--注意只有(n-1)個點

                
            //int stack[size] ; int top = 2 ;
                stack[0= 0 ; stack[1= 1 ; stack[2= 2 ; top  = 2 ;

                
            forint i=3; i<inn; i++ )
                {
                    
            while( top>=1&&xmult( point[i], point[stack[top]], point[stack[top-1]] )>=-1*eps ) 
                        top
            -- ;//順時針方向--刪除棧頂元素
                    stack[++top] = i ;//新元素入棧
                }
                
            /*
                for( int i=0; i<=top; i++ )
                {
                //printf( "%lf===%lf\n",point[stack[i]].x, point[stack[i]].y ) ;
                cout << point[stack[i]].x << "====" << point[stack[i]].y << endl ;
                }
                
            */
            }

            double flen_poly()
            {
            //計算凸包的周長
                double len = 0.0 ; double x1, x2, y1, y2 ;
                
            forint i=0; i<top; i++ ) {
                    x1 
            = point[stack[i+1]].x ; x2 = point[stack[i]].x ;
                    y1 
            = point[stack[i+1]].y ; y2 = point[stack[i]].y ;
                    len 
            += fdist( x1, y1, x2, y2 ) ;
                }
                x1 
            = point[stack[0]].x ; x2 = point[stack[top]].x ;
                y1 
            = point[stack[0]].y ; y2 = point[stack[top]].y ;
                len 
            += fdist( x1, y1, x2, y2 ) ;

                
            return len ;
            }

            double farea_poly( int n, POINT poly[] )
            {
                
            double area = 0.0 ; double s1 = 0.0 , s2 = 0.0 ;
                
            forint i=0; i<n; i++ )
                {
                    s1 
            += poly[stack[(i+1)%n]].y * poly[stack[i%n]].x ;
                    s2 
            += poly[stack[(i+1)%n]].y * poly[stack[(i+2)%n]].x ;
                }

                
            return fabs( s1 - s2 ) / 2 ;
            }

            void process()
            {
                gramham() ;
            //保存好凸包的點在stack[]中

                outlen 
            = flen_poly() ;

                outlen 
            += PI * 2.0 * inr ;
            }

            void output()
            {
                printf( 
            "%0.0lf\n", outlen ) ;
            }

            int main()
            {
                
            //freopen( "fc.in", "r", stdin ) ;
                
            //freopen( "fc.out","w",stdout ) ;

                
            //freopen( "in.txt", "r", stdin ) ;

                
            //while( scanf( "%d %d", &inn, &inr ) != EOF ) 
                scanf( "%d %d"&inn, &inr ) ;
                {
                    input() ;

                    process() ;

                    output() ;
                }

                
            return 0 ;
            }
            狠狠综合久久综合88亚洲| 一本久久知道综合久久| 亚洲人成网站999久久久综合| 久久国产成人精品麻豆| 四虎国产精品免费久久5151| 久久综合九色综合网站| 精品久久久久香蕉网| 精品久久久久久| 99久久777色| 色8激情欧美成人久久综合电| 精品久久久无码21p发布| 无码国内精品久久人妻蜜桃 | 99久久综合狠狠综合久久| 青青草原综合久久| 韩国无遮挡三级久久| 久久亚洲国产午夜精品理论片 | 久久久久久a亚洲欧洲aⅴ| 久久夜色精品国产网站| 99久久中文字幕| 久久99精品久久久久久噜噜| 久久99精品国产麻豆宅宅| 久久人人爽人人爽人人片AV东京热 | 人人狠狠综合久久亚洲| 久久婷婷人人澡人人爽人人爱| 97久久国产露脸精品国产| 久久精品亚洲中文字幕无码麻豆| 国产精品免费久久久久影院| 国产精品热久久毛片| 久久久久久青草大香综合精品| 久久夜色精品国产噜噜噜亚洲AV | 99久久精品免费看国产一区二区三区| 天天躁日日躁狠狠久久 | 午夜不卡久久精品无码免费| 国产精品久久久久久久久免费| 久久99久久无码毛片一区二区| 国内精品九九久久精品 | 色综合久久综合中文综合网| 久久99热国产这有精品| 久久本道久久综合伊人| 人妻精品久久久久中文字幕69| 国产精品亚洲综合专区片高清久久久 |