POJ-2007

G++要用%f而C++要用%lf
极角排序

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <utility>
using namespace std;
struct P
{
    double x, y;
    P() {}
    P(double x, double y) : x(x), y(y) {}
    P operator +(const P &p)
    {
        return P(x + p.x, y + p.y);
    }
    P operator -(const P &p)
    {
        return P(x - p.x, y - p.y);
    }
    P operator *(const double &d)
    {
        return P(x * d, y * d);
    }
    P operator /(const double &d)
    {
        return P(x / d, y / d);
    }
    bool operator ==(const P &p)
    {
        return x == p.x && y == p.y;
    }
    P operator =(const P &p)
    {
        x = p.x, y = p.y;
        return *this;
    }
    double det(const P &p)
    {
        return x * p.y - y * p.x;
    }
    double dot(const P &p)
    {
        return x * p.x + y * p.y;
    }
};

P in_arr[500];

bool Graham_cmp(P a, P b)
{
    P origin(0.0, 0.0);
    return (a - origin).det(b - origin) > 0;
}


int main()
{
//    freopen("in.in", "r", stdin);
    int i = 0;
    while(scanf("%lf %lf", &in_arr[i].x, &in_arr[i].y) != EOF)
    {
        i += 1;
    }
    sort(in_arr + 1, in_arr + i, Graham_cmp);
    for(int j = 0; j < i; ++j) printf("(%.0lf,%.0lf)\n", in_arr[j].x, in_arr[j].y);
return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值