gt22 icon

Untitled

gt22 | PRO | 10/01/18 08:18:30 PM UTC | 0 ⭐ | 572 👁️ | Never ⏰ | []
Java |

1.15 KB

|

None

|

0 👍

/

0 👎

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.function.Function;
 
public class O1753 {
 
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] s = r.readLine().split(" ");
        int h = Integer.parseInt(s[0]), H = Integer.parseInt(s[1]), L = Integer.parseInt(s[2]);
        if(h >= H / 2) {
            System.out.println(0);
            return;
        }
        Function<Double, Double> func = (a) -> { // H * Cos(a) / 2 - h * Ctg(a)
            double cos = Math.cos(a);
            return H * cos / 2 - h * cos / Math.sin(a);
        };
        Function<Double, Double> derivative = (a) -> { //h * Csc^2(a) - H * Sin(a)/2
            double sin = Math.sin(a);
            return h / (sin * sin) - H * sin / 2;
        };
        final double EPS = 1e-7;
        double start = Math.asin(h / H);
        double end = Math.PI / 2;
        while(end > start) {
            double x = (start + end) / 2;
            double val = derivative.apply(x);
            if(val > EPS) {
                start = x;
            } else if(val < -EPS) {
                end = x;
            } else {
                end = x;
                break;
            }
        }
        System.out.println(func.apply(end));
    }
 
}

Comments