Submission #69880352


Source Code Expand

/*
*            /$$           /$$
*           |__/          |__/
*  /$$$$$$$$ /$$ /$$$$$$$$ /$$  /$$$$$$
* |____ /$$/| $$|____ /$$/| $$ /$$__  $$
*    /$$$$/ | $$   /$$$$/ | $$| $$  \ $$
*   /$$__/  | $$  /$$__/  | $$| $$  | $$
*  /$$$$$$$$| $$ /$$$$$$$$| $$|  $$$$$$$
* |________/|__/|________/|__/ \____  $$
*                                   | $$
*                                   | $$
*                                   |__/
*/
//hj23308保佑我
//Missile保佑我
/*
* 醒了在梦里挣扎,不觉黯淡了朝霞
*/
/*
* 我很高兴你没有忘了我,但是我现在更希望你已经忘了我了。
* 希望在你的记忆中,我只是尘土一撮,从你的全世界路过,然后四散飞扬不留下一点痕迹,而你要不回头的往前走。
* 我更希望我只是从你的全世界路过,只是路过
*/
/*
* 只是我在十字路口守了太久,守到黄沙如雨掩埋一切痕迹,才发现自己等的人已经离开了。
*/
/*
* 听我的 别回头 回头就可能会泪流满面,会被黄沙掩埋,所以即使痛苦也要向前走
*/
/*
* 我听到了「天行健」的回响,这是一个伟大斗士的不息自强;
* 我听到了「破万法」的回响,这是一个黑道打手的守护欲望;
* 我看见了「生生不息」的激荡,这是一个骗子的伟大乐章!
*/
/*
* 我用虚假的面具照顾着细腻的感情;
* 我以华丽的衣物下藏着腐烂的血肉;
* 当我摘下面具,褪去衣物,即便是我最亲近的人,也无法直视我
*/
#include<bits/stdc++.h>
using namespace std;
mt19937 engine(chrono::steady_clock().now().time_since_epoch().count());
const long double eps=1e-8;
const long double inf=1e16;
int t;
long double tA,tB;
long double Ax,Ay,Bx,By,Cx,Cy,Dx,Dy;
long double calc(long double t)
{
	long double AX=Bx-Ax,AY=By-Ay,BX=Dx-Cx,BY=Dy-Cy;
	long double kA=(AX/sqrtl(AX*AX+AY*AY)),kB=(BX/sqrtl(BX*BX+BY*BY)),kC=(AY/sqrtl(AX*AX+AY*AY)),kD=(BY/sqrtl(BX*BX+BY*BY));
	if(t>tB) {
		return (Ax+kA*t-Dx)*(Ax+kA*t-Dx)+(Ay+kC*t-Dy)*(Ay+kC*t-Dy);
	}
	return (Ax+kA*t-Cx-kB*t)*(Ax+kA*t-Cx-kB*t)+(Ay+kC*t-Cy-kD*t)*(Ay+kC*t-Cy-kD*t);
}
long double solve()
{
	tA=sqrtl((Ax-Bx)*(Ax-Bx)+(Ay-By)*(Ay-By)),tB=sqrtl((Cx-Dx)*(Cx-Dx)+(Cy-Dy)*(Cy-Dy));
	if(tA<tB) {
		swap(tA,tB);
		swap(Ax,Cx),swap(Ay,Cy),swap(Bx,Dx),swap(By,Dy);
	}
	long double Ans=inf;
	long double l=0,r=tB;
	while(l+eps<r) {
		long double mid=(l+r)/2;
		if(calc(mid)-calc(mid+eps)>=0) l=mid;
		else r=mid;
	}
	Ans=min(Ans,calc(l));
	l=tB,r=tA;
	while(l+eps<r) {
		long double mid=(l+r)/2;
		if(calc(mid)-calc(mid+eps)>=0) l=mid;
		else r=mid;
	}
	Ans=min(Ans,calc(l));
	return sqrtl(Ans);
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--) {
		cin>>Ax>>Ay>>Bx>>By>>Cx>>Cy>>Dx>>Dy;
		cout<<fixed<<setprecision(12)<<solve()<<"\n";
	}
	return 0;
}

Submission Info

Submission Time
Task E - Closest Moment
User Ziziq
Language C++ 20 (gcc 12.2)
Score 450
Code Size 3006 Byte
Status AC
Exec Time 1264 ms
Memory 3888 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 1
AC × 11
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 02_large_00.txt, 02_large_01.txt, 02_large_02.txt, 02_large_03.txt, 02_large_04.txt, 02_large_05.txt, 02_large_06.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3756 KiB
01_small_00.txt AC 971 ms 3736 KiB
01_small_01.txt AC 780 ms 3888 KiB
01_small_02.txt AC 1032 ms 3888 KiB
02_large_00.txt AC 1248 ms 3736 KiB
02_large_01.txt AC 1249 ms 3728 KiB
02_large_02.txt AC 1247 ms 3724 KiB
02_large_03.txt AC 1248 ms 3884 KiB
02_large_04.txt AC 1264 ms 3764 KiB
02_large_05.txt AC 1263 ms 3792 KiB
02_large_06.txt AC 30 ms 3820 KiB