题目链接

题意 : 对输入的点极角排序

思路 : 极角排序方法

#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>

using namespace std;

struct point
{
    double x,y;
}p[50],pp;
double cross(point a,point b,point c)
{
    return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y) ;
}
bool cmp(point a,point b)
{
    int cr = cross(a,b,pp) ;//判断顺时针还是逆时针
    if(cr > 0) return true ;
    else if(cr < 0) return false ;
}
int main()
{
    int cnt = 0;
    while (scanf("%lf %lf",&p[cnt].x,&p[cnt].y) != EOF)
    {
        ++cnt;
    }
    pp.x = pp.y = 0 ;
    sort(p+1,p+cnt,cmp);
    for (int i = 0 ; i < cnt ; i++)
    {
        cout<<"("<<p[i].x<<","<<p[i].y<<")"<<endl;
    }
    return 0;
}

 

posted on 2014-08-28 14:07  枫、  阅读(146)  评论(0编辑  收藏  举报