Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1.  
  2. import javax.print.DocFlavor;
  3. import java.io.*;
  4. import java.lang.reflect.Array;
  5. import java.math.BigInteger;
  6. import java.util.*;
  7. import java.util.concurrent.ThreadLocalRandom;
  8.  
  9. import static java.lang.Math.*;
  10.  
  11. @SuppressWarnings("Duplicates")
  12.  
  13. public class solveLOL {
  14. FastScanner in;
  15. PrintWriter out;
  16. boolean systemIO = true, multitests = false;
  17.  
  18. lol arr[];
  19. ArrayList<TreeSet<lol>> mas = new ArrayList<>();
  20. int mx = 0;
  21.  
  22. public void solve() {
  23. int n = in.nextInt() * 2;
  24. arr = new lol[n];
  25. for (int i = 0; i < n; ++i) {
  26. int x1 = in.nextInt(), y1 = in.nextInt(), x2 = in.nextInt(), y2 = in.nextInt();
  27. arr[i] = new lol((y1 - y2), (x2 - x1), -((y1 - y2) * x1 + (x2 - x1) * y1));
  28. int p = gcd(gcd(abs(arr[i].a), abs(arr[i].b)), abs(arr[i].c));
  29. if (p != 0)
  30. arr[i] = new lol(arr[i].a / p, arr[i].b / p, arr[i].c / p);
  31. }
  32. Arrays.sort(arr, (o1, o2) -> o1.a != o2.a ? Long.compare(o1.a, o2.a) : (o1.b != o2.b) ? Long.compare(o1.b, o2.b) : Long.compare(o1.c, o2.c));
  33. mas.add(new TreeSet<>((o1, o2) -> o1.a != o2.a ? Long.compare(o1.a, o2.a) : (o1.b != o2.b) ? Long.compare(o1.b, o2.b) : Long.compare(o1.c, o2.c)));
  34. mas.get(mx).add(arr[0]);
  35. for (int i = 1; i < n; ++i) {
  36. if (arr[i].a == arr[i - 1].a && arr[i].b == arr[i - 1].b) {
  37. mas.get(mx).add(arr[i]);
  38. } else {
  39. mx++;
  40. mas.add(new TreeSet<>((o1, o2) -> o1.a != o2.a ? Long.compare(o1.a, o2.a) : (o1.b != o2.b) ? Long.compare(o1.b, o2.b) : Long.compare(o1.c, o2.c)));
  41. mas.get(mx).add(arr[i]);
  42. }
  43. }
  44. int k = mas.get(0).first().c;
  45. for (lol x : mas.get(0)) {
  46. if (x != mas.get(0).first() && check(x.c - k)) {
  47. double ans = x.c - k;
  48. System.out.println(String.format("%8.10f", ans).replace(',', '.'));
  49. System.exit(0);
  50. }
  51. }
  52. System.out.println("-1.000000000");
  53. }
  54.  
  55. boolean check(int res) {
  56. for (int i = 0; i < mas.size(); i++) {
  57. for (lol k : mas.get(i)) {
  58. if (!mas.get(i).contains(new lol(k.a, k.b, k.c + res)) && !mas.get(i).contains(new lol(k.a, k.b, k.c - res))) {
  59. return false;
  60. }
  61. }
  62. }
  63. return true;
  64. }
  65. /*
  66. 3
  67. 0 0 0 1
  68. 1 0 1 1
  69. 2 0 2 1
  70. 3 0 3 1
  71. 0 0 1 0
  72. 0 1 1 1
  73. */
  74.  
  75.  
  76.  
  77. class lol {
  78. int a, b, c;
  79.  
  80.  
  81. lol(int A, int B, int C) {
  82. this.a = A;
  83. this.b = B;
  84. this.c = C;
  85. }
  86. }
  87.  
  88. int gcd(int a, int b) {
  89. return b == 1 ? gcd(b, a % b) : a;
  90. }
  91.  
  92. void shuffleArray(long[] ar) {
  93. Random rnd = ThreadLocalRandom.current();
  94. for (int i = ar.length - 1; i > 0; i--) {
  95. int index = rnd.nextInt(i + 1);
  96. long a = ar[index];
  97. ar[index] = ar[i];
  98. ar[i] = a;
  99. }
  100. }
  101.  
  102. long[] readArray(int size_) {
  103. long[] ar = new long[size_];
  104. for (int i = 0; i < size_; i++) {
  105. ar[i] = in.nextLong();
  106. }
  107. return ar;
  108. }
  109.  
  110. void printArray(long[] ar) {
  111. for (long k : ar) {
  112. System.out.print(k + " ");
  113. }
  114. System.out.println();
  115. }
  116.  
  117. void reverseArray(long[] ar) {
  118. for (int i = 0, j = ar.length - 1; i < j; i++, j--) {
  119. long a = ar[i];
  120. ar[i] = ar[j];
  121. ar[j] = a;
  122. }
  123. }
  124.  
  125.  
  126. class FastScanner {
  127. BufferedReader br;
  128. StringTokenizer st;
  129.  
  130. FastScanner(File f) {
  131. try {
  132. br = new BufferedReader(new FileReader(f));
  133. } catch (FileNotFoundException e) {
  134. e.printStackTrace();
  135. }
  136. }
  137.  
  138. FastScanner(InputStream f) {
  139. br = new BufferedReader(new InputStreamReader(f));
  140. }
  141.  
  142. String nextLine() {
  143. try {
  144. return br.readLine();
  145. } catch (IOException e) {
  146. return null;
  147. }
  148. }
  149.  
  150. String next() {
  151. while (st == null || !st.hasMoreTokens()) {
  152. try {
  153. st = new StringTokenizer(br.readLine());
  154. } catch (IOException e) {
  155. e.printStackTrace();
  156. }
  157. }
  158. return st.nextToken();
  159. }
  160.  
  161. int nextInt() {
  162. return Integer.parseInt(next());
  163. }
  164.  
  165. long nextLong() {
  166. return Long.parseLong(next());
  167. }
  168.  
  169. double nextDouble() {
  170. return Double.parseDouble(next());
  171. }
  172.  
  173. }
  174.  
  175. //String.format("%8.3f", ans).replace(',', '.')
  176. private void run() throws IOException {
  177. if (systemIO) {
  178. in = new solveLOL.FastScanner(System.in);
  179. out = new PrintWriter(System.out);
  180. } else {
  181. in = new solveLOL.FastScanner(new File("aplusb.in"));
  182. out = new PrintWriter(new File("aplusb.out"));
  183. }
  184. for (int t = multitests ? in.nextInt() : 1; t-- > 0; )
  185. solve();
  186.  
  187. out.close();
  188. }
  189.  
  190. public static void main(String[] arg) throws IOException {
  191. new solveLOL().run();
  192. }
  193.  
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement