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 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
这道题能够用二分做,由于要求矩阵最大值的最小值,所以最后A矩阵的每一个元素和B矩阵的每一个元素差值都小于等于一个数时最小,所以从0到10^9枚举差值,然后依据范围二分。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int n,m,i,j;
double l,r,mid,a,b,c,d,a1,a2,b1,b2,c1,c2,d1,d2,t1,t2,s1,s2;
while(scanf("%lf%lf%lf%lf",&a,&b,&c,&d)!=EOF)
{
l=0.0,r=1000000000.0;
for(i=1;i<=100000;i++){
mid=(l+r)/2.0;
a1=a+mid;a2=a-mid;
b1=b+mid;b2=b-mid;
c1=c+mid;c2=c-mid;
d1=d+mid;d2=d-mid;
t1=min(min(a1*d1,a1*d2),min(a2*d1,a2*d2));
t2=min(min(b1*c1,b1*c2),min(b2*c1,b2*c2));
s1=max(max(a1*d1,a1*d2),max(a2*d1,a2*d2));
s2=max(max(b1*c1,b1*c2),max(b2*c1,b2*c2));
if(t1<=s2 && t2<=s1)r=mid;
else l=mid;
}
double ans=l;
printf("%.11f\n",ans);
}
return 0;
}
codeforces Looksery Cup 2015 H Degenerate Matrix的更多相关文章
- codeforces Looksery Cup 2015 H Degenerate Matrix 二分 注意浮点数陷阱
#include <cstdio> #include <cstring> #include <algorithm> #include <string> ...
- Looksery Cup 2015 H. Degenerate Matrix 数学
H. Degenerate Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/ ...
- codeforces Looksery Cup 2015 D. Haar Features
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viol ...
- codeforces Looksery Cup 2015 C. The Game Of Parity
There are n cities in Westeros. The i-th city is inhabited by ai people. Daenerys and Stannis play t ...
- Looksery Cup 2015 Editorial
下面是题解,做的不好.下一步的目标是rating涨到 1800,没打过几次cf A. Face Detection Author: Monyura One should iterate through ...
- Looksery Cup 2015 A. Face Detection 水题
A. Face Detection Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/pro ...
- Looksery Cup 2015 B. Looksery Party 暴力
B. Looksery Party Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/pro ...
- codeforces VK Cup 2015 - Qualification Round 1 B. Photo to Remember 水题
B. Photo to Remember Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/522/ ...
- Looksery Cup 2015 C. The Game Of Parity —— 博弈
题目链接:http://codeforces.com/problemset/problem/549/C C. The Game Of Parity time limit per test 1 seco ...
随机推荐
- [暑假集训--数位dp]hdu5898 odd-even number
For a number,if the length of continuous odd digits is even and the length of continuous even digits ...
- css3实现连续不断的波浪
给的波浪要比容器大,然后在左边准备一个相同的,注意,波浪头尾要能衔接起来,接着运动的长度为波浪的宽度,然后不断重复就好了
- 关于cookie使用的一些问题
保存cookie后提取出来发现字符串是被编码过的,需要decodeURIComponent进行下解码才可以 设置cookie setCookie(c_name, value, expiredays) ...
- Office 365 切换语言设置
The steps of changing the language: Click “Setting ”>”Office 365 Setting” ...
- 14深入理解C指针之---指针与内存分配
一.内存的含义 1.定义:物理内存是固定,逻辑内存是非常灵活的 2.特征: 1).逻辑内存最终必须映射到物理内存才能作用 2).逻辑内存每次映射可能到不同的物理内存 3).逻辑内存与物理内存的链接通过 ...
- linux 时间模块 三
LINUX的时钟中断中涉及至二个全局变量一个是xtime,另一个则是jiffies.有一个与时间有关的时钟:实时时钟(RTC),这是一个硬件时钟,用来持久存放系统时间,系统关闭后靠主板上的微型电池保持 ...
- ajax请求Url加参数的使用方法
var cId = $(this).data('claim-id');var adoptUrl = "<?php echo $this->createUrl('claim/app ...
- AC日记——最大子树和 洛谷 P1122
题目描述 小明对数学饱有兴趣,并且是个勤奋好学的学生,总是在课后留在教室向老师请教一些问题.一天他早晨骑车去上课,路上见到一个老伯正在修剪花花草草,顿时想到了一个有关修剪花卉的问题.于是当日课后,小明 ...
- osstatus -9801 workerman websocket 小程序不带端口
帮事业部的同事,解决问题,坑总结 小程序出现,osstatus -9801 情况好多,说一下配置环境可解决的方法和问题 tls 1.2, php 5.6+, nginx, workerman 做的 w ...
- iOS -- 原生NSStream实现socket
- (void)startSocket:(NSString *)address andPort:(int)port { CFReadStreamRef readRef; CFWriteStreamRe ...