当前位置: 代码迷 >> 综合 >> POJ 2007 计算几何水题
  详细解决方案

POJ 2007 计算几何水题

热度:5   发布时间:2024-01-20 20:22:55.0

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

水之....

/************************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;
}


  相关解决方案