Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Fast {
- public static void main(String[] args) {
- int n = StdIn.readInt();
- Point points[] = new Point[n];
- for (int i = 0; i < n; i++) {
- points[i] = (new Point(StdIn.readInt(), StdIn.readInt()));
- }
- Arrays.sort(points);
- //Map<Double, ArrayList<Point>> map = new HashMap<Double, ArrayList<Point>>();
- TreeMap<Double, ArrayList<Point>> sortedMap = new TreeMap<Double, ArrayList<Point>>();
- Double slope = 0.0;
- for (int i = 0; i < n; i++) {
- for (int j = i + 1; j < n; j++) {
- slope = points[i].slopeTo(points[j]);
- if (!sortedMap.containsKey(slope)) {
- sortedMap.put(slope, new ArrayList<Point>());
- sortedMap.get(slope).add(points[i]);
- }
- if (!sortedMap.get(slope).contains(points[j]))
- sortedMap.get(slope).add(points[j]);
- }
- }
- //sortedMap.putAll(map);
- for (ArrayList<Point> list : sortedMap.values()) {
- int count = 0;
- if (list.size() >= 4){
- count = 0;
- for (Point p : list) {
- StdOut.print(p);
- count++;
- if (count < list.size())
- StdOut.print(" -> ");
- }
- count++;
- if (count < sortedMap.size()){
- StdOut.print("\n");
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment