Codeforces 549H. Degenerate Matrix 二分
二分绝对值,推断是否存在对应的矩阵
1 second
256 megabytes
standard input
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||.
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 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.
1 2
3 4
0.2000000000
1 0
0 1
0.5000000000
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 二分的更多相关文章
- codeforces Looksery Cup 2015 H Degenerate Matrix 二分 注意浮点数陷阱
#include <cstdio> #include <cstring> #include <algorithm> #include <string> ...
- 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 ...
- Looksery Cup 2015 H. Degenerate Matrix 数学
H. Degenerate Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/ ...
- [Codeforces 1199C]MP3(离散化+二分答案)
[Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...
- CodeForces 549H | 二分答案
参考了这个博客哇 #include<cstdio> #include<algorithm> #include<cstring> #define Max(a,b,c, ...
- CodeForces 670D1 暴力或二分
今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1 This problem is given in two versions that diff ...
- codeforces 895B XK Segments 二分 思维
codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\( ...
- Codeforces 626C Block Towers(二分)
C. Block Towers time limit per test:2 seconds memory limit per test:256 megabytes input:standard inp ...
- codeforces 803D Magazine Ad(二分+贪心)
Magazine Ad 题目链接:http://codeforces.com/contest/803/problem/D ——每天在线,欢迎留言谈论. 题目大意: 给你一个数字k,和一行字符 例: g ...
随机推荐
- HTML5初步——新的表单元素和属性
HTML5初步--新的表单元素和属性 HTML5初步--新的表单元素和属性 <!DOCTYPE html> <html> <head> <meta chars ...
- 为什么国外程序员爱用苹果Mac电脑?(转)
Mac 在国外很受欢迎,尤其是在 设计/web开发/IT 人员圈子里.普通用户喜欢 Mac 可以理解,毕竟 Mac 设计美观,简单好用,没有病毒.那么为什么专业人士也对 Mac 情有独钟呢?从个人使用 ...
- windows 2003 自动安全设置
@echo offecho.echo.echo.echo 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓echo.echo.echo windows 2003 自动安全设置程序 echo. ec ...
- hdu1540(线段树)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1540 题意:是一条线上的点,D x是破坏这个点,Q x是表示查询以x所在的最长的连续的点的个数,R是恢 ...
- 特里-HDOJ-1671
Phone List Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Codeforces Round #277.5 (Div. 2)---B. BerSU Ball (贪心)
BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- 《循序渐进Oracle》部分笔记
1.不要用户名/密码 直接/as sysdba 是操作系统认证方式,改变安全方式 sqlnet.ora 里SQLNET.AUTHENTICATION_SERVICES=(NTS)表示启动操作系统认证; ...
- POJThe Doors AND NYIST 有趣的问题
POJThe Doors AND NYIST 有趣的问题 题目链接:pid=227" target="_blank">Click Here~ 题目分析: 给你横纵坐 ...
- android client随机验证码生成函数
由于该项目使用验证码.自己找了一些资料.尽量把这个验证码做出来.代码不是很,較的简单,以下给大家看看我是怎么实现该功能的: 源代码地址下载:http://download.csdn.net/detai ...
- 动态加载资源文件(ResourceDictionary)
原文:动态加载资源文件(ResourceDictionary) 在xaml中控件通过绑定静态资源StaticResource来获取样式Style有多种方式: 1.在项目的启动文件App中<App ...