Codeforces 549 H. Degenerate Matrix binary

Source: Internet
Author: User

Codeforces 549 H. Degenerate Matrix binary

 

Returns the binary absolute value and determines whether a matrix exists.

 

H. Degenerate Matrix time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

The determinant of a matrix 2? ×? 2 is defined as follows:

A matrix is called degenerate if its determinant is equal to zero.

The norm |A| Of a matrixAIs defined as a maximum of absolute values of its elements.

You are given a matrix. Consider any degenerate matrixBSuch that norm |A? -?B| Is minimum possible. Determine |A? -?B|.

Input

The first line contains two integersAAndB(|A| ,? |B|? ≤? 109), the elements of the first row of matrixA.

The second line contains two integersCAndD(|C| ,? |D|? ≤? 109) the elements of the second row of matrixA.

Output

Output a single real number, the minimum possible value of |A? -?B|. Your answer is considered to be correct if its absolute or relative error does not exceed 10? -? 9.

Sample test (s) input
1 23 4
Output
0.2000000000
Input
1 00 1
Output
0.5000000000
Note

In the first sample matrixBIs

In the second sample matrixBIs


import java.util.*;public class Main{double a,b,c,d;double[][] range = new double[4][2];double getMin(double L,double R,double l,double r){   return Math.min(L*l,Math.min(L*r,Math.min(R*l,R*r)));}double getMax(double L,double R,double l,double r){   return Math.max(L*l,Math.max(L*r,Math.max(R*l,R*r)));}boolean check(double e){range[0][0]=a-e; range[0][1]=a+e; // xrange[1][0]=b-e; range[1][1]=b+e; // yrange[2][0]=c-e; range[2][1]=c+e; // zrange[3][0]=d-e; range[3][1]=d+e; // wdouble A=getMin(range[0][0],range[0][1],range[3][0],range[3][1]);double B=getMax(range[0][0],range[0][1],range[3][0],range[3][1]);double C=getMin(range[1][0],range[1][1],range[2][0],range[2][1]);double D=getMax(range[1][0],range[1][1],range[2][0],range[2][1]);if((A>=C&&A<=D)||(B>=C&&B<=D)||(C>=A&&C<=B)||(D>=A&&D<=B)) return true;return false;}double Search(){double low=0.00000,high=100000000000.;int T_T=170;while(T_T-->0){double mid=(low+high)/2.;if(check(mid)==true) high=mid;else low=mid;}return high; }Main(){Scanner in = new Scanner(System.in);a=in.nextDouble(); b=in.nextDouble(); c=in.nextDouble(); d=in.nextDouble();System.out.printf("%.12f\n",Search());}public static void main(String[] args){new Main();}}


 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.