Codeforces 549H. Degenerate Matrix 二分

66 篇文章 0 订阅


二分绝对值,判断是否存在相应的矩阵

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 matrix A is defined as a maximum of absolute values of its elements.

You are given a matrix . Consider any degenerate matrix B such that norm ||A - B|| is minimum possible. Determine||A - B||.

Input

The first line contains two integers a and b (|a|, |b| ≤ 109), the elements of the first row of matrix A.

The second line contains two integers c and d (|c|, |d| ≤ 109) the elements of the second row of matrix A.

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 2
3 4
output
0.2000000000
input
1 0
0 1
output
0.5000000000
Note

In the first sample matrix B is 

In the second sample matrix B is 


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; // x
		range[1][0]=b-e; range[1][1]=b+e; // y
		range[2][0]=c-e; range[2][1]=c+e; // z
		range[3][0]=d-e; range[3][1]=d+e; // w

		double 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();
	}
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,Codeforces Round 511 (Div. 1)是一个比赛的名称。然而,引用内容中没有提供与这个比赛相关的具体信息或问题。因此,我无法回答关于Codeforces Round 511 (Div. 1)的问题。如果您有关于这个比赛的具体问题,请提供更多的信息,我将尽力回答。 #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces Round 867 (Div. 3)(A题到E题)](https://blog.csdn.net/wdgkd/article/details/130370975)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值