首页 > 其他分享 >Looksery Cup 2015-H. Degenerate Matrix(浮点数二分)

Looksery Cup 2015-H. Degenerate Matrix(浮点数二分)

时间:2023-06-12 18:03:08浏览次数:55  
标签:Matrix Cup 浮点数 mid b1 b2 d1 d2 matrix


原题链接


H. Degenerate Matrix



time limit per test



memory limit per test



input



output


determinant of a matrix 2 × 2



Looksery Cup 2015-H. Degenerate Matrix(浮点数二分)_ide


degenerate

norm ||A|| of a matrix A

You are given a matrix 

Looksery Cup 2015-H. Degenerate Matrix(浮点数二分)_ide_02

. Consider any degenerate matrix B such that norm ||A - B|| is minimum possible. Determine ||A - B||.

Input


a and b (|a|, |b| ≤ 109), the elements of the first row of matrix A.

c and d (|c|, |d| ≤ 109) the elements of the second row of matrix A.


Output


||A - B||. Your answer is considered to be correct if its absolute or relative error does not exceed 10 - 9.


Examples


input


1 23 4


output


0.2000000000


input


1 00 1


output


0.5000000000


假设矩阵的四个值为a, b, (第一行两个元素)c, d(第二行两个元素) , 二分枚举最大值mid, 那么a, b, c, d每个数都可以上下浮动mid, 算出a * d的最大值r1, 最小值l1, b * c的最大值r2, 最小值l2, 若[l1, r1]和[l2, r2]相交则可在最大值为mid之内构成一个B矩阵

#include <cstdio>
#include <iostream>
#define maxn 1005 
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
	
	ll a, b, c, d;
	scanf("%I64d%I64d%I64d%I64d", &a, &b, &c, &d);
	double l = 0, r = 2e9, a1, a2, b1, b2, c1, c2, d1, d2;
	for(int i = 0; i < 100000; i++){
		double mid = (l + r) / 2;
		a1 = a + mid, a2 = a - mid;
		b1 = b + mid, b2 = b - mid;
		c1 = c + mid, c2 = c - mid;
		d1 = d + mid, d2 = d - mid;
		double t1 = max(max(a1 * d1, a1 * d2), max(a2 * d1, a2 * d2));
		double t2 = min(min(a1 * d1, a1 * d2), min(a2 * d1, a2 * d2));
		double t3 = max(max(b1 * c1, b1 * c2), max(b2 * c1, b2 * c2));
		double t4 = min(min(b1 * c1, b1 * c2), min(b2 * c1, b2 * c2));
		if(t4 <= t1 && t2 <= t3)
		 r = mid;
		else
		 l = mid;
	}
	printf("%.9lf\n", l);
	return 0;
}




标签:Matrix,Cup,浮点数,mid,b1,b2,d1,d2,matrix
From: https://blog.51cto.com/u_16158872/6464594

相关文章

  • 新的权限模型Matrix data access structure介绍
    这是我的第494篇原创文章,写于2023年6月8日。2021年11月2日,PowerApps博客的博文 AnnouncingPublicPreviewformodernizebusinessunits 宣布了ModernizedBusinessUnits开启Publicpreview阶段,到本文写作时,这个Feature已经GeneralAvailable了。相关功能介绍请参考官方文档......
  • [LeetCode] 1351. Count Negative Numbers in a Sorted Matrix
    Givena mxn matrix grid whichissortedinnon-increasingorderbothrow-wiseandcolumn-wise,return thenumberof negative numbersin grid.Example1:Input:grid=[[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]Output:8Explanation:Thereare......
  • c#中十六进制字符串转单精度浮点数
    1varcountBytes=newbyte[]{66,12,25,217};2varcountHexStr=ToHexStrFromByte(countBytes.ToArray());3uintnum=uint.Parse(countHexStr,System.Globalization.NumberStyles.AllowHexSpecifier);4byte[]floatVals......
  • 浮点数转字符串
    浮点数转字符串usingUnityEngine;publicclassJuse:MonoBehaviour{floata=2;floatb=6666.6666f;voidStart(){Debug.Log(a.ToString("#00"));//输出:02Debug.Log(a.ToString("#00.00"));//输出:02.00......
  • upc 8378: Floating-Point Numbers(模拟浮点数运算)
    8378:Floating-PointNumbers时间限制:1Sec  内存限制:128MB提交:10  解决:4[提交][状态][讨论版][命题人:admin]题目描述Inthisproblem,weconsiderfloating-pointnumberformats,datarepresentationformatstoapproximaterealnumbersoncomputers.S......
  • CF101234A Hacker Cups and Balls【二分+线段树】
    Description给一个长度为n的排列,对它做m次操作,每次对[l,r]区间内进行升序/降序排序。问最后的序列处于最中心的数是多少(n为奇数)。Solution是一类没有写过的题,参考题解。二分答案,对于当前的mid,将大于等于mid的数设置为1,小于mid的数设置为0。这样一来,叶结点的值......
  • Spring boot 使用 jpa 动态插入@DynamicInsert和动态更新@DynamicUpdate(动态指部分或
    @DynamicInsert属性:设置为true,设置为true,表示insert对象的时候,生成动态的insert语句,如果这个字段的值是null就不会加入到insert语句当中.默认false。比如希望数据库插入日期或时间戳字段时,在对象字段为空的情况下,表字段能自动填写当前的sysdate。@DynamicUpdate属性:设置为tru......
  • leetcode 566. Reshape the Matrix
    InMATLAB,thereisaveryusefulfunctioncalled'reshape',whichcanreshapeamatrixintoanewonewithdifferentsizebutkeepitsoriginaldata.You'regivenamatrixrepresentedbyatwo-dimensionalarray,andtwopositiveintegersr......
  • leetcode 766. Toeplitz Matrix
    AmatrixisToeplitzifeverydiagonalfromtop-lefttobottom-righthasthesameelement.NowgivenanMxNmatrix,return True ifandonlyifthematrixisToeplitz. Example1:Input:matrix=[[1,2,3,4],[5,1,2,3],[9,5,1,2]]Output:TrueExplanation:12......
  • leetcode 378. Kth Smallest Element in a Sorted Matrix
    Givenanxnmatrixwhereeachoftherowsandcolumnsaresortedinascendingorder,findthekthsmallestelementinthematrix.Notethatitisthekthsmallestelementinthesortedorder,notthekthdistinctelement.Example:matrix=[[1,5,9......