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 ...
随机推荐
- IPython:一种交互式计算和开发环境
一 键盘快捷键 - Ctrl-P 或上箭头键 后向搜索命令历史中以当前输入的文本开头的命令 - Ctrl-N 或下箭头键 前向搜索命令历史中以当前输入的文本开头的命令 - Ctrl-R ...
- from __future__ import unicode_literals, absolute_import
Q:python模块中的相对导入,绝对导入,有些地方会写 from __future__ import absolute_import 希望有个更详细的讲解. A: 相对导入:在不指明 package ...
- Dumb Bones(uva 10529)
题意:给定n,表示要放n个骨牌,每次放下骨牌,有可能向左倒的概率为pl,向右倒的概率为pr,如果倒下,会将那一侧的骨牌全部推倒,可以选择位置先后放骨牌,问说一种放骨牌次数最少的期望是多少. /* 设d ...
- CF 451E Devu and Flowers
可重集的排列数 + 容斥原理 对于 \(\{A_1 * C_1, A _2 * C_2, \cdots, A_n * C_n\}\)这样的集合来说, 设 \(N = \sum_{i = 1} ^ n ...
- JAVA特性面试题:
1.简要介绍java程序的健壮性. 答:JAVA程序会在编译和运行的时候自动的检测可能出现的错误,而且它是一种强类型语言,对于类型的检查很严格,而且它的垃圾回收机制也有效的避免了内存的泄漏. 2.为什 ...
- 标准C程序设计七---51
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- U3D层的运用
在操作 LayerMask 时常令一些初学者摸不着头脑下面简单说一下层的开关方法:1.首先引入'|'.'&'.'~'的概念与(交集):10000001 & 10000100 == 10 ...
- mysql tinyint bit
Java bit 对应 mysql tinyint(1) false = 0 ,true = 1.
- LeetCode OJ--Add Two Numbers
http://oj.leetcode.com/problems/add-two-numbers/ 将用链表表示的两个数相加,(2 -> 4 -> 3) + (5 -> 6 -> ...
- luogu P3811 【模板】乘法逆元
题目背景 这是一道模板题 题目描述 给定n,p求1~n中所有整数在模p意义下的乘法逆元. 输入输出格式 输入格式: 一行n,p 输出格式: n行,第i行表示i在模p意义下的逆元. 输入输出样例 输入样 ...