gt22

Untitled

Oct 1st, 2018
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.function.Function;
  5.  
  6. public class O1753 {
  7.  
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
  10.         String[] s = r.readLine().split(" ");
  11.         int h = Integer.parseInt(s[0]), H = Integer.parseInt(s[1]), L = Integer.parseInt(s[2]);
  12.         if(h >= H / 2) {
  13.             System.out.println(0);
  14.             return;
  15.         }
  16.         Function<Double, Double> func = (a) -> { // H * Cos(a) / 2 - h * Ctg(a)
  17.             double cos = Math.cos(a);
  18.             return H * cos / 2 - h * cos / Math.sin(a);
  19.         };
  20.         Function<Double, Double> derivative = (a) -> { //h * Csc^2(a) - H * Sin(a)/2
  21.             double sin = Math.sin(a);
  22.             return h / (sin * sin) - H * sin / 2;
  23.         };
  24.         final double EPS = 1e-7;
  25.         double start = Math.asin(h / H);
  26.         double end = Math.PI / 2;
  27.         while(end > start) {
  28.             double x = (start + end) / 2;
  29.             double val = derivative.apply(x);
  30.             if(val > EPS) {
  31.                 start = x;
  32.             } else if(val < -EPS) {
  33.                 end = x;
  34.             } else {
  35.                 end = x;
  36.                 break;
  37.             }
  38.         }
  39.         System.out.println(func.apply(end));
  40.     }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment