POJ 2007 计算几何水题

大意是说将凸多边形顶点按逆时针排序,起点是原点且没有第二象限的点。

水之....

/***********************
 *Creator:Sevenster    *
 *Time:2012.08.01 13:47*
 *PID:POJ 2007         *
 ***********************/
#include<iostream>
#include<cmath>
#include<algorithm>
#define EPS 1e-6
using namespace std;

class CPoint
{
public:
       double x, y;
       CPoint( double a= 0, double b= 0 )
       {
               this->x= a;
               this->y= b;
       }
}point[55];

class CVector
{
public:
       double x, y;
       CVector( double a= 0, double b= 0 )
       {
                this->x= a;
                this->y= b;
       }
};

CVector operator-( CPoint b, CPoint a )
{
        return CVector( b.x- a.x, b.y- a.y );
}

double operator^( CVector p,CVector q )
{
       return p.x* q.y- p.y* q.x;
}

int sign( double x )
{
    if( fabs(x)<EPS )
        return 0;
    return x>0?1:-1;
}

double length( CVector p )
{
       return sqrt( fabs( p.x* p.x+ p.y* p.y ) );
}

bool cmp( CPoint p,CPoint q )
{
     int flag=sign( ( p- point[0])^( q- point[0]) );
     if(  flag==0 )
         return length( p- point[0] )<length( q- point[0] );
     return flag==1;
}

int main()
{
    //freopen( "test.in","r",stdin );
    //freopen( "test.out","w",stdout );
    int pcnt=0;
    while( scanf( "%lf %lf", &point[pcnt].x, &point[pcnt].y )!=EOF )
           pcnt++;
    sort( point+ 1, point+ pcnt, cmp );
    for( int i= 0; i< pcnt; i++ )
         printf( "(%.0lf,%.0lf)\n", point[i].x, point[i].y );
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值