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

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. 智能生活 “视”不可挡——首届TCL杯HTML5智能电视开发大赛等你来挑战

    http://www.csdn.net/article/2014-06-04/2820063-TCL-Smart-TV-Innovation-Competation

  2. POJ 2676/2918 数独(dfs)

    思路:记录每行每列每一个宫已经出现的数字就可以.数据比較弱 另外POJ 3074 3076 必须用剪枝策略.但实现较麻烦,还是以后学了DLX再来做吧 //Accepted 160K 0MS #incl ...

  3. OpenLayers学习笔记4——使用jQuery UI实现測量对话框

    OpenLayers学习最好的方式就是跟着其自带的演示样例进行学习,另外对web前端的开发设计要了解,慢慢积累,这样在一般的小项目中应该是足够用了. 本篇參照量測demo实现对话框形式的量測,抛砖引玉 ...

  4. H3C TE老版本OSPF正确配置

    R1配置: ---------------------------------------------------- # sysname RT1# super password level 3 cip ...

  5. ASPF简介

    ASPF是一种应用层状态检测技术,它通过与NAT和ALG等技术的组合应用,实现对应用层协议状态的处理和检测. 1.1  产生背景 随着计算机技术和网络技术的普及,网络安全问题也越来越得到关注.防火墙作 ...

  6. SE 2014年4月14日

    一. 概述BGP的特点 BGP协议是一种距离矢量协议,基于TCP的179端口,BGP协议不会动态的学习路由,只能将IGP协议学习到的或者静态路由注入到BGP中,成为BGP路由,BGP路由携带有丰富的路 ...

  7. Effective C++:条款28:避免返回 handles 指向对象内部成员

    (一) 有时候为了让一个对象尽量小,能够把数据放在另外一个辅助的struct中,然后再让一个类去指向它.看以下的代码: class Point { public: Point(int x, int y ...

  8. ecshop 后台批量上传商品 完整上传

    ecshop 后台批量上传商品,之所以无法上传,是因为后台上传php文件方法中没有导入商品原图路径 将ecshop根目录中的admin/goods_batch.php文件全部修改为 <?php ...

  9. hdu1500 (排序+单调队列优化 )

    从n根筷子里面, 选择k+8个集合的筷子,每个集合三根筷子, A<=B<=C, 费用是(A-B)^2, 问最小的费用是多少. 将n根筷子排序之后,可以知道A和B的下标一定是连续的. 比如有 ...

  10. .net读取异步Post的内容

    //读取微信Post过来的XML内容                 byte[] input = HttpContext.Current.Request.BinaryRead(HttpContext ...