POJ 2007 简单几何

来源:互联网 发布:手机qq显示mac在线吗 编辑:程序博客网 时间:2024/05/16 15:04

既然是整数,就不要写double了.

既然是整数,就用叉积吧,别用atan2 丢失精度.

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <string>#include <algorithm>using namespace std;const int maxn = 50+3;struct Point{    int x;    int y;}p[maxn],P0;int Mult(Point p0, Point p1, Point p2)  //叉积{    return (p1.x-p0.x)*(p2.y-p0.y) - (p2.x-p0.x)*(p1.y-p0.y);}int cmp(const Point &p1, const Point &p2)  //排序函数{    return Mult(P0,p1,p2)>0;}int main(){#ifndef ONLINE_JUDGE    freopen("in","r",stdin);#endif    int n = 0;    while(cin>>p[n].x>>p[n].y)    {        n++;    }    P0 = p[0];    sort(p+1,p+n,cmp);    for(int i = 0; i < n; i++)    {        cout<<"("<<p[i].x<<","<<p[i].y<<")"<<endl;    }    return 0;}

我试着写了下用double的(仅仅求角度换成了double 比较斜率大小 用了精度判断(<1e-8) ) 依然WA

无解...这种题目还是老老实实 写整数的吧.多好...能不丢失精度就不丢失精度~

原创粉丝点击