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 ...
随机推荐
- Linux System Programming 学习笔记(五) 进程管理
1. 进程是unix系统中两个最重要的基础抽象之一(另一个是文件) A process is a running program A thread is the unit of activity in ...
- 转 Python爬虫实战一之爬取糗事百科段子
静觅 » Python爬虫实战一之爬取糗事百科段子 首先,糗事百科大家都听说过吧?糗友们发的搞笑的段子一抓一大把,这次我们尝试一下用爬虫把他们抓取下来. 友情提示 糗事百科在前一段时间进行了改版,导致 ...
- 安装部署k8s-版本-1.13
1.环境准备 # 统一hosts cat /etc/hosts 10.0.0.10 k8s-master 10.0.0.20 k8s-node1 10.0.0.30 k8s-node2 # 同步时间 ...
- 【ZJOI2016】大♂森林
题目描述 小Y家里有一个大森林,里面有 $n$ 棵树,编号从 $1$ 到 $n$ .一开始这些树都只是树苗,只有一个节点,标号为 $1$ .这些树都有一个特殊的节点,我们称之为生长节点,这些节点有生长 ...
- IntelliJ IDEA 常用快捷键总结
个人使用频率的高低排序: Alt+enter 代码提示 Alt+7 查看类的方法 Alt+insert 生成get和set方法 ...
- soursTree新建过程.md
网上博客 https://www.cnblogs.com/tian-xie/p/6264104.html 主要的推送流程 完成所有项目的远程推送工作 点击git工作流选择第二个建立新的版本; 输入发布 ...
- java正则过虑字符
public static void main(String[] args) { String testrString = "{\"abc\" : \"[123 ...
- 邁向IT專家成功之路的三十則鐵律 鐵律二:IT專家專業之道–專精
在IT技術的領域當中有許多的類別,若要細分那可真是難以一一列舉,但常見的大致有軟體研發工程師.韌體研發工程師.系統分析師.網路工程師.系統工程師.維護工程師.動畫設計師.製圖工程師.以及各類別的專業電 ...
- n个平面把空间最多分成几个部分?
题目: n个平面把空间最多分成几个部分? 解答: 1条直线可以把平面分成2部分,2条直线最多可以把平面分成4部分, 3条直线最多可以把平面分成几部分,4条直线呢?你能不能想出n条直线最多可以把平面分成 ...
- 【ActiveMQ】2.spring Boot下使用ActiveMQ
在spring boot下使用ActiveMQ,需要一下几个条件 1.安装并启动了ActiveMQ,参考:http://www.cnblogs.com/sxdcgaq8080/p/7919489.ht ...