既然是整数,就不要写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; }
无解...这种题目还是老老实实 写整数的吧.多好...能不丢失精度就不丢失精度~