Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Fast {
- public static void main(String[] args) throws IOException{
- FileWriter fw = new FileWriter("visualPoints.txt", false);
- BufferedWriter write = new BufferedWriter(fw);
- int n = StdIn.readInt();
- Point[] points = new Point[n];
- for(int i = 0; i < n; i++) { //Add points
- points[i] = new Point(StdIn.readInt(), StdIn.readInt());
- }
- Set<ArrayList<Point>> ff = new HashSet<>();
- ArrayList<ArrayList<Point>> pl = new ArrayList<ArrayList<Point>>();
- ArrayList<Point> seg = new ArrayList<>();
- for(int a = 0; a < n; a++) {
- Point[] temp = Arrays.copyOf(points, points.length);
- double curSlope = 0;
- Arrays.sort(temp, temp[a].BY_SLOPE_ORDER);
- curSlope = temp[0].slopeTo(temp[1]);
- for(int b = 1; b < n; b++) {
- if(seg.isEmpty()) {
- seg.add(temp[b]);
- curSlope = temp[0].slopeTo(temp[b]);
- }
- else if(curSlope == temp[0].slopeTo(temp[b])) {
- seg.add(temp[b]);
- if(b == n - 1 && seg.size() >= 3) {
- seg.add(temp[0]);
- pl.add(seg);
- seg = new ArrayList<>();
- }
- }
- else{
- if(seg.size() >= 3) {
- seg.add(temp[0]);
- pl.add(seg);
- seg = new ArrayList<>();
- }
- seg.clear();
- seg.add(temp[b]);
- curSlope = temp[0].slopeTo(temp[b]);
- }
- }
- }
- for(ArrayList<Point> col : pl) Collections.sort(col);
- ff.addAll(pl);
- pl.clear();
- pl.addAll(ff);
- ArrayList<Point> faf = new ArrayList<>();
- for(ArrayList<Point> col: pl)StdOut.print(col+"\n");
- Iterator<ArrayList<Point>> index = pl.iterator();
- while(index.hasNext()) {
- faf = index.next();
- StdOut.print(faf.size()+":(");
- for(int i = 0; i < faf.size(); i++) {
- StdOut.print(faf.get(i).getX()+", "+faf.get(i).getY());
- if(i < faf.size()-1) StdOut.print(" -> ");
- }
- StdOut.print(")\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement