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||.

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 

这道题能够用二分做,由于要求矩阵最大值的最小值,所以最后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;
}
时间: 2024-11-05 21:33:46

codeforces Looksery Cup 2015 H Degenerate Matrix的相关文章

codeforces Looksery Cup 2015 H Degenerate Matrix 二分 注意浮点数陷阱

#include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <iostream> using namespace std; bool fun(double l1,double r1,double l2,double r2){ return (l1 <= r2 && l1

codeforces Looksery Cup 2015 D. Haar Features

The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model

Looksery Cup 2015 Editorial

下面是题解,做的不好.下一步的目标是rating涨到 1800,没打过几次cf A. Face Detection Author: Monyura One should iterate through each 2x2 square and check if it is possible to rearrange letters in such way they they form the word "face". It could be done i.e. by sorting al

Codeforces VK Cup 2015 Wild Card Round 1 (AB)

比赛链接:http://codeforces.com/contest/522 A. Reposts time limit per test:1 second memory limit per test:256 megabytes One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started

Looksery Cup 2015——AFace Detection

The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table t

Codeforces VK Cup 2015 A.And Yet Another Bracket Sequence(后缀数组+平衡树+字符串)

这题做得比较复杂..应该有更好的做法 题目大意: 有一个括号序列,可以对其进行两种操作: ·        向里面加一个括号,可以在开头,在结尾,在两个括号之间加. ·        对当前括号序列进行循环移动,即把最后一个括号拿到开头来. 上述两种操作可以做任意次,要求添加最少的括号使得原序列变成一个合法括号序列.如果有多种可能,输出字典序最小的那一个."(" < ")". 题解: 首先计算左括号和右括号的数量,可以知道,不妨假设左括号的数量大于右括号 那么

codeforces #549 Looksery Cup 部分题解

掉Rating快乐~~ A.Face Detection 题目大意:给定一个n?m的矩阵,求有多少2?2的子矩形满足单词"face"的每个字母在矩形中恰好出现一次 签到题 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 55 using namespace std; int n,m,ans; char map[M

Codeforces gym Hello 2015 Div1 E

Codeforces gym 100570 problem E (一种处理动态最长回文子串问题的方法) Problem 给一个长度为N的字符串S,字符集是'a'-'z'.进行Q次操作,操作分三种.一,修改位置X的字符为C:二,查询以P位置为中心的最长回文子串的长度,并输出:三,查询以P与P+1的中间位置为中心的最长回文子串的长度,并输出. More 第二种操作子串长度为奇数,一定存在:第三种操作子串长度为偶数,若不存在,输出 -1. Limits Time Limit(ms): 4000(1s足

Codeforces gym Hello 2015 Div1 B and Div2 D

Codeforces gym 100571 problem D Problem 给一个有向图G<V,E>和源点S,边的属性有长度L和颜色C,即E=<L,C>.进行Q次询问,每次给定一个点X,输出S到X的最短路的长度(不存在则输出 -1).但要求S到X的路径中相邻两条边颜色不一样. Limits Time Limit(ms): 1000 Memory Limit(MB): 256 |V|, |E|: [1, 10^5] X, S: [1, |V| ] L: [1, 10^9] |C|