Advertisement
Guest User

Untitled

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