Guest User

Untitled

a guest
Dec 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. public class Fast {
  2.     public static void main(String[] args) {
  3.         int n = StdIn.readInt();
  4.         Point points[] = new Point[n];
  5.         for (int i = 0; i < n; i++) {
  6.             points[i] = (new Point(StdIn.readInt(), StdIn.readInt()));
  7.         }
  8.  
  9.         Arrays.sort(points);
  10.         //Map<Double, ArrayList<Point>> map = new HashMap<Double, ArrayList<Point>>();
  11.         TreeMap<Double, ArrayList<Point>> sortedMap = new TreeMap<Double, ArrayList<Point>>();
  12.         Double slope = 0.0;
  13.         for (int i = 0; i < n; i++) {
  14.             for (int j = i + 1; j < n; j++) {
  15.                 slope = points[i].slopeTo(points[j]);
  16.                 if (!sortedMap.containsKey(slope)) {
  17.                     sortedMap.put(slope, new ArrayList<Point>());
  18.                     sortedMap.get(slope).add(points[i]);
  19.                 }
  20.                 if (!sortedMap.get(slope).contains(points[j]))
  21.                     sortedMap.get(slope).add(points[j]);
  22.             }
  23.         }
  24.         //sortedMap.putAll(map);
  25.         for (ArrayList<Point> list : sortedMap.values()) {
  26.             int count = 0;
  27.             if (list.size() >= 4){
  28.                 count = 0;
  29.                 for (Point p : list) {
  30.                     StdOut.print(p);
  31.                     count++;
  32.                     if (count < list.size())
  33.                         StdOut.print(" -> ");
  34.                 }
  35.                 count++;
  36.                 if (count < sortedMap.size()){
  37.                     StdOut.print("\n");
  38.                 }
  39.             }
  40.         }
  41.     }
  42. }
Add Comment
Please, Sign In to add comment