POJ - 2007 极角排序(Java 实现)
将所有的点按逆时针输出
import java.io.*;
import java.util.*;
public class Main {
static class Point implements Comparable<Point>{
double x, y;
@Override
public int compareTo(Point a) {
return (int)cross(a);
}
public double cross(Point a){
return a.x*y-x*a.y;
}
}
static final int N = 10005;
static final int inf = 0x3f3f3f3f;
static final double eps = 1e-6;
static Point a[] = new Point[N];
public static void main(String[] args) {
Scanner cin = new Scanner(new InputStreamReader(System.in));
int n = 0;
while (cin.hasNext()) {
if (a[n] == null)
a[n] = new Point();
a[n].x = cin.nextDouble();
a[n].y = cin.nextDouble();
n++;
}
Arrays.sort(a, 1, n);
for (int i = 0; i < n; i++) {
System.out.printf("(%.0f,%.0f)\n", a[i].x, a[i].y);
}
cin.close();
}
}