CF1886B Fear of the Dark 题解

思路

这题可以二分+check,但是好像会被卡精度

其实,这题分类讨论就好了。

只经过一个圆;经过两个圆,需要两个圆相交。

这题具体实现的时候可以使用结构体/类的思想,把一个圆想成一个类,判断的时候不用写两遍了

代码:

#include <bits/stdc++.h>
using namespace std;
int T;
double x1, y1, x2, y2, x3, y3;
bool c1(double x, double y, double dou, double x1, double y1) {
	return (x1 - x) * (x1 - x) + (y1 - y) * (y1 - y) < dou * dou;
}
bool c2(double x1, double y1, double x2, double y2, double dou) {
	return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) < (dou * 2) * (dou * 2);
}
bool check(double dou) {
	if (c1(x2, y2, dou, 0, 0) && c1(x2, y2, dou, x1, y1)) return true;
	if (c1(x3, y3, dou, 0, 0) && c1(x3, y3, dou, x1, y1)) return true;
	if (c2(x2, y2, x3, y3, dou)) {
		if (c1(x2, y2, dou, 0, 0) && c1(x3, y3, dou, x1, y1)) return true;
		if (c1(x3, y3, dou, 0, 0) && c1(x3, y2, dou, x1, y1)) return true;
	}
	return 0;
}
int main() {
	ios :: sync_with_stdio(false);
	cin >> T;
	while (T--) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		double l = 0, r = 5e3, ans = r, mid;
		while (abs(r - l) > 1e-9) {
			mid = (r + l) / 2;
			if (check(mid)) {
				ans = min(ans, mid);
				r = mid;
			} else l = mid;
		}
		printf("%.9lf\n", ans);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值