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

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

Codeforces 549H. Degenerate Matrix 二分的更多相关文章

  1. codeforces Looksery Cup 2015 H Degenerate Matrix 二分 注意浮点数陷阱

    #include <cstdio> #include <cstring> #include <algorithm> #include <string> ...

  2. codeforces Looksery Cup 2015 H Degenerate Matrix

    The determinant of a matrix 2 × 2 is defined as follows: A matrix is called degenerate if its determ ...

  3. Looksery Cup 2015 H. Degenerate Matrix 数学

    H. Degenerate Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/ ...

  4. [Codeforces 1199C]MP3(离散化+二分答案)

    [Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...

  5. CodeForces 549H | 二分答案

    参考了这个博客哇 #include<cstdio> #include<algorithm> #include<cstring> #define Max(a,b,c, ...

  6. CodeForces 670D1 暴力或二分

    今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that diff ...

  7. codeforces 895B XK Segments 二分 思维

    codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\( ...

  8. Codeforces 626C Block Towers(二分)

    C. Block Towers time limit per test:2 seconds memory limit per test:256 megabytes input:standard inp ...

  9. codeforces 803D Magazine Ad(二分+贪心)

    Magazine Ad 题目链接:http://codeforces.com/contest/803/problem/D ——每天在线,欢迎留言谈论. 题目大意: 给你一个数字k,和一行字符 例: g ...

随机推荐

  1. 浏览器url传参中文时得到null的解决方法

    在写一个中文参数需求的时候遇到了以下问题,经过半天的测试和各种编码,以及网上一些有用没用的资料尝试终于解决    比如下面的url地址:http://travel.widget.baike.com:8 ...

  2. poj1836--Alignment(dp,最长上升子序列变形)

    Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13319   Accepted: 4282 Descri ...

  3. 开发指南专题4:JEECG高速微云开发平台--JEECG开发环境的搭建

    开发指南专题4:JEECG微云高速开发平台开发环境搭建 1. JEECG开发环境搭建 JEECG推荐的开发环境为Myeclipse8.5/Eclipse3.7+JDK1.6+Tomcat6.0 1.1 ...

  4. OC -- 第一个类

    OC -- 第一个类 类名:Car 属性:轮胎个数.时速 行为:跑 完整写一个类:类的声明和实现 1.    类的声明 代码: // NSObject 再Foundation框架中 #import & ...

  5. solr4.9r+ Eclipse 4.3+ tomcat 7.5 +winds7(二)

    尊重原创,原文地址:http://blog.csdn.net/chunlei_zhang/article/details/38778945 这另外一种方法是将solr项目部署到tomcat上,执行to ...

  6. Struts2 学习第一步准备工作

    第一步:安装下载MyEclispe10 对于MyEclispe的下载安装就不再详述了. 第二步:下载Struts-2.3.15 Struts-2.3.15下载地址: http://struts.apa ...

  7. Mutex(测量)

    游标共享怎样使用Mutex kks 使用mutex以便保护对于下述基于parent cursor父游标和子游标child cursor的一系列操作 对于父游标parent cursor的操作: 基于发 ...

  8. Webserver管理系列:1、安装Windows Server 2008

    简单了解下server: 1U: 2U: 3U: 在安装Windows Server 2008之前我们先了解下Windows Server 2008: Windows Server 2008是微软一个 ...

  9. 推测的手机型号和cpu模型

    <span style="font-size:18px;">推断手机型号:</span> <span style="font-size:18 ...

  10. Linux下多线程查看工具(pstree、ps、pstack) (转)

    1. pstree pstree以树结构显示进程$ pstree -p work | grep adsshd(22669)---bash(22670)---ad_preprocess(4551)-+- ...