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

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. Java程序猿之从菜鸟到职场高手的必看

    J2SE之入门引导            Java基础系列之初识JAVA                                           Java基础系列之Java语法       ...

  2. python实现人人网用户数据爬取及简单分析

    这是之前做的一个小项目.这几天刚好整理了一些相关资料,顺便就在这里做一个梳理啦~ 简单来说这个项目实现了,登录人人网并爬取用户数据.并对用户数据进行分析挖掘,终于效果例如以下:1.存储人人网用户数据( ...

  3. hdu2159(二维完全背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2159 题意:打怪,还有最后一级,忍耐度有限m,问在杀怪数量上限为s的情况下能否获取n经验而通关,且忍耐 ...

  4. php反射类 ReflectionClass

    什么是php反射类,顾名思义,能够理解为一个类的映射.举个样例: class fuc {        //定义一个类static function ec() {echo '我是一个类';}}$cla ...

  5. Linux scp文件复制

    scp是 secure copy的缩写, scp是linux系统下基于ssh登陆进行安全的远程文件拷贝命令.  1.scp命令的用处:  scp在网络上不同的主机之间复制文件,它使用ssh安全协议传输 ...

  6. hosts文件导致无法访问网站

    前段时间有人反映无论怎么样都无法在自己的电脑上访问法兰克官网,那台电脑的DNS也无法解析,通过查看hosts文件后发现,原来该电脑的hosts文件木马修改过了,屏蔽了相关的域名,删除新增的或者用其他机 ...

  7. zoj1610(线段树)

    题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 题意:在0-8000长的线段里面,按先后次序依次覆盖颜色, ...

  8. 一个用js写的接口http调试程序

    公司有非常多手机app的项目.手机app又要常常訪问后台提交与查询数据. 所曾经端app与后台的开发与測试过程中接口调试是一个常常要做的工作. 而每当出现一个BUG,前端appproject师与后台p ...

  9. HttpClient 网络优化

    HttpClient 网络优化 尽管Android官网推荐在2.3及后续版本中使用HttpURLConnection作为网络开发首选类,但在连接管理和线程安全方面,HttpClient还是具有很大优势 ...

  10. Swift的属性,方法,下标脚本以及继承

    从这篇章节起,Swift编程语言指南大部分的重要内容在于概念,代码并非太多.理解Swift的面向对象理念,语法以及类结构,构造析构过程对于非常好的应用Swift语言将会有比較大的帮助. 属性 存储属性 ...