Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.print.DocFlavor;
- import java.io.*;
- import java.lang.reflect.Array;
- import java.math.BigInteger;
- import java.util.*;
- import java.util.concurrent.ThreadLocalRandom;
- import static java.lang.Math.*;
- @SuppressWarnings("Duplicates")
- public class solveLOL {
- FastScanner in;
- PrintWriter out;
- boolean systemIO = true, multitests = false;
- lol arr[];
- ArrayList<TreeSet<lol>> mas = new ArrayList<>();
- int mx = 0;
- public void solve() {
- int n = in.nextInt() * 2;
- arr = new lol[n];
- for (int i = 0; i < n; ++i) {
- double x1 = in.nextDouble(), y1 = in.nextDouble(), x2 = in.nextDouble(), y2 = in.nextDouble();
- arr[i] = new lol((y1 - y2), (x2 - x1), javabad(-((y1 - y2) * x1 + (x2 - x1) * y1)));
- double p = gcd(gcd(abs(arr[i].a), abs(arr[i].b)), abs(arr[i].c));
- arr[i] = new lol(arr[i].a / p, arr[i].b / p, arr[i].c / p);
- }
- Arrays.sort(arr, (o1, o2) -> o1.a != o2.a ? Double.compare(o1.a, o2.a) : (o1.b != o2.b) ? Double.compare(o1.b, o2.b) : Double.compare(o1.c, o2.c));
- mas.add(new TreeSet<>((o1, o2) -> o1.a != o2.a ? Double.compare(o1.a, o2.a) : (o1.b != o2.b) ? Double.compare(o1.b, o2.b) : Double.compare(o1.c, o2.c)));
- mas.get(mx).add(arr[0]);
- for (int i = 1; i < n; ++i) {
- if (arr[i].a == arr[i - 1].a && arr[i].b == arr[i - 1].b) {
- mas.get(mx).add(arr[i]);
- } else {
- mx++;
- mas.add(new TreeSet<>((o1, o2) -> o1.a != o2.a ? Double.compare(o1.a, o2.a) : (o1.b != o2.b) ? Double.compare(o1.b, o2.b) : Double.compare(o1.c, o2.c)));
- mas.get(mx).add(arr[i]);
- }
- }
- double k = mas.get(0).first().c;
- for (lol x : mas.get(0)) {
- if (x != mas.get(0).first() && check(javabad(x.c - k))) {
- double ans = x.c - k;
- System.out.println(String.format("%8.10f", ans).replace(',', '.'));
- System.exit(0);
- }
- }
- System.out.println("-1.000000000");
- }
- boolean check(double res) {
- for (int i = 0; i < mas.size(); i++) {
- for (lol k : mas.get(i)) {
- if (!mas.get(i).contains(new lol(k.a, k.b, javabad(k.c + res))) && !mas.get(i).contains(new lol(k.a, k.b, javabad(k.c - res)))) {
- return false;
- }
- }
- }
- return true;
- }
- /*
- 3
- 0 0 0 1
- 1 0 1 1
- 2 0 2 1
- 3 0 3 1
- 0 0 1 0
- 0 1 1 1
- */
- double javabad(double p) {
- if (Math.abs(p) == 0) {
- return 0;
- } else {
- return p;
- }
- }
- class lol {
- double a, b, c;
- lol(double A, double B, double C) {
- this.a = A;
- this.b = B;
- this.c = C;
- }
- }
- double gcd(double a, double b) {
- return b == 1 ? gcd(b, a % b) : a;
- }
- void shuffleArray(long[] ar) {
- Random rnd = ThreadLocalRandom.current();
- for (int i = ar.length - 1; i > 0; i--) {
- int index = rnd.nextInt(i + 1);
- long a = ar[index];
- ar[index] = ar[i];
- ar[i] = a;
- }
- }
- long[] readArray(int size_) {
- long[] ar = new long[size_];
- for (int i = 0; i < size_; i++) {
- ar[i] = in.nextLong();
- }
- return ar;
- }
- void printArray(long[] ar) {
- for (long k : ar) {
- System.out.print(k + " ");
- }
- System.out.println();
- }
- void reverseArray(long[] ar) {
- for (int i = 0, j = ar.length - 1; i < j; i++, j--) {
- long a = ar[i];
- ar[i] = ar[j];
- ar[j] = a;
- }
- }
- class FastScanner {
- BufferedReader br;
- StringTokenizer st;
- FastScanner(File f) {
- try {
- br = new BufferedReader(new FileReader(f));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- FastScanner(InputStream f) {
- br = new BufferedReader(new InputStreamReader(f));
- }
- String nextLine() {
- try {
- return br.readLine();
- } catch (IOException e) {
- return null;
- }
- }
- String next() {
- while (st == null || !st.hasMoreTokens()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
- int nextInt() {
- return Integer.parseInt(next());
- }
- long nextLong() {
- return Long.parseLong(next());
- }
- double nextDouble() {
- return Double.parseDouble(next());
- }
- }
- //String.format("%8.3f", ans).replace(',', '.')
- private void run() throws IOException {
- if (systemIO) {
- in = new solveLOL.FastScanner(System.in);
- out = new PrintWriter(System.out);
- } else {
- in = new solveLOL.FastScanner(new File("aplusb.in"));
- out = new PrintWriter(new File("aplusb.out"));
- }
- for (int t = multitests ? in.nextInt() : 1; t-- > 0; )
- solve();
- out.close();
- }
- public static void main(String[] arg) throws IOException {
- new solveLOL().run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement