既然是整数,就不要写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
无解...这种题目还是老老实实 写整数的吧.多好...能不丢失精度就不丢失精度~
本文介绍了一种通过使用整数运算而非浮点数来避免精度损失的方法,并提供了一个具体的几何问题解决实例,展示了如何利用叉积进行点排序,以确保结果的准确性。
709

被折叠的 条评论
为什么被折叠?



