Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Fast {
  5. public static void main(String[] args) throws IOException{
  6. FileWriter fw = new FileWriter("visualPoints.txt", false);
  7. BufferedWriter write = new BufferedWriter(fw);
  8. int n = StdIn.readInt();
  9. Point[] points = new Point[n];
  10.  
  11. for(int i = 0; i < n; i++) { //Add points
  12. points[i] = new Point(StdIn.readInt(), StdIn.readInt());
  13. }
  14. Set<ArrayList<Point>> ff = new HashSet<>();
  15. ArrayList<ArrayList<Point>> pl = new ArrayList<ArrayList<Point>>();
  16. ArrayList<Point> seg = new ArrayList<>();
  17. for(int a = 0; a < n; a++) {
  18. Point[] temp = Arrays.copyOf(points, points.length);
  19. double curSlope = 0;
  20. Arrays.sort(temp, temp[a].BY_SLOPE_ORDER);
  21. curSlope = temp[0].slopeTo(temp[1]);
  22.  
  23. for(int b = 1; b < n; b++) {
  24. if(seg.isEmpty()) {
  25. seg.add(temp[b]);
  26. curSlope = temp[0].slopeTo(temp[b]);
  27. }
  28. else if(curSlope == temp[0].slopeTo(temp[b])) {
  29. seg.add(temp[b]);
  30. if(b == n - 1 && seg.size() >= 3) {
  31. seg.add(temp[0]);
  32. pl.add(seg);
  33. seg = new ArrayList<>();
  34. }
  35. }
  36. else{
  37. if(seg.size() >= 3) {
  38. seg.add(temp[0]);
  39. pl.add(seg);
  40. seg = new ArrayList<>();
  41. }
  42. seg.clear();
  43. seg.add(temp[b]);
  44. curSlope = temp[0].slopeTo(temp[b]);
  45. }
  46. }
  47. }
  48. for(ArrayList<Point> col : pl) Collections.sort(col);
  49. ff.addAll(pl);
  50. pl.clear();
  51. pl.addAll(ff);
  52. ArrayList<Point> faf = new ArrayList<>();
  53. for(ArrayList<Point> col: pl)StdOut.print(col+"\n");
  54. Iterator<ArrayList<Point>> index = pl.iterator();
  55. while(index.hasNext()) {
  56. faf = index.next();
  57.  
  58. StdOut.print(faf.size()+":(");
  59. for(int i = 0; i < faf.size(); i++) {
  60. StdOut.print(faf.get(i).getX()+", "+faf.get(i).getY());
  61. if(i < faf.size()-1) StdOut.print(" -> ");
  62. }
  63. StdOut.print(")\n");
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement