import java.util.Scanner; public class PolygonArea_TernarySearchACC{ static double Area(double k1, double k2, double k3) // What is the area of a triangle with sides k1, k2, k3? { // Heron. double s = (k1 + k2 + k3) / 2.0; return Math.sqrt(s * (s - k1) * (s - k2) * (s - k3)); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); double[] l = new double[4]; for(int i = 0; i < 4; i++) l[i] = sc.nextDouble(); // Assume the starting point is in the origin. // By rotating the shape, we can assume that the point opposite to the starting point is on the positive x-axis. // Now do binary search on this point opposite the starting point, using only some elementary geometry. // By splitting the tetragon into two triangles, calculations become much simpler. double mink = Math.max(Math.abs(l[0] - l[1]), Math.abs(l[2] - l[3])); double maxk = Math.min(l[0] + l[1], l[2] + l[3]); double answer = 0; while(maxk - mink > 0.0000001) { double k1 = (mink*2 + maxk) / 3.0d; double k2 = (mink + maxk*2) / 3.0d; double answer1 = Area(k1, l[0], l[1]) + Area(k1, l[2], l[3]); double answer2 = Area(k2, l[0], l[1]) + Area(k2, l[2], l[3]); if(answer1 >= answer2) maxk = k2; if(answer2 > answer1) mink = k1; answer = answer1; } System.out.println(answer); } }