Codeforces Round #465 (Div. 2) C. Fifa and Fafa(圆问题,数论)

本文探讨了一种在有限范围内寻找Wi-Fi接入点的最佳位置的方法,旨在最小化未被无线信号覆盖的区域面积,并确保特定点位于该覆盖范围之外。文章提供了一个具体的算法实现案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C. Fifa and Fafa
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of r meters (this range can be chosen by Fifa) from its position. Fifa must put the access point inside the flat which has a circular shape of radius R. Fifa wants to minimize the area that is not covered by the access point inside the flat without letting Fafa or anyone outside the flat to get access to the internet.

The world is represented as an infinite 2D plane. The flat is centered at (x1, y1) and has radius R and Fafa's laptop is located at (x2, y2), not necessarily inside the flat. Find the position and the radius chosen by Fifa for his access point which minimizes the uncovered area.

Input

The single line of the input contains 5 space-separated integers R, x1, y1, x2, y2 (1 ≤ R ≤ 105|x1|, |y1|, |x2|, |y2| ≤ 105).

Output

Print three space-separated numbers xap, yap, r where (xap, yap) is the position which Fifa chose for the access point and r is the radius of its range.

Your answer will be considered correct if the radius does not differ from optimal more than 10 - 6 absolutely or relatively, and also the radius you printed can be changed by no more than 10 - 6 (absolutely or relatively) in such a way that all points outside the flat and Fafa's laptop position are outside circle of the access point range.

Examples
input
Copy
5 3 3 1 1
output
3.7677669529663684 3.7677669529663684 3.914213562373095
input
Copy
10 5 5 5 15
output
5.0 5.0 10.0

题目大意:现在有一个半径为r,圆心为(x1,y1)的圆,和一个(x2,y2)的点,现在要求规定圆内找一个点形成一个圆使得点在圆外(或圆上)且使得规定圆的范围尽可能和圆覆盖

解题思路:根据题意,(x2,y2)这个点有两种情况,一种在规定圆内部,一种是在规定圆外部,在外部的话,要求算的圆其实就是规定的圆,如果在规定圆的内部要分两种情况

一种是正好是圆心,这样的话,我们就可以在圆心到圆上画一个半径为r/2的圆,因为要考虑到使得规定圆与要求的圆尽量重合,那么点在要求圆上是最好的选择

还有一种是不再圆心上,那我们要求圆的圆心一定是在通过点和规定圆圆心的射线上,以点为段的射线上,那么半径R就是r+点与规定圆的距离了,至于求要求圆的圆心,我们可以根据相似三角形的原则,利用算出的半径R和圆心到点的距离,相似两个三角形,一个三角形是规定圆与点的三角形,一个是要求圆圆点与点形成的三角形即可

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

LL x1,x2,r,yy1,y2;
double rr,rx,ry;
int main()
{
	scanf("%lld %lld %lld %lld %lld", &r, &x1, &yy1, &x2, &y2);
	if(x1==x2 && yy1==y2)
	{
		printf("%.10lf %.10lf %.10lf\n",double(x1*1.0+r/2.0),double(yy1*1.0),double(r/2.0));
		return 0;
	}
	if((x1-x2)*(x1-x2)+(yy1-y2)*(yy1-y2)>=r*r)
	{
		printf("%0.10lf %0.10lf %0.10lf\n",double(x1*1.0),double(yy1*1.0),double(r*1.0));
		return 0;
	}
	//以下上相似三角形的算法
	rr= (sqrt((x1-x2)*(x1-x2)+(yy1-y2)*(yy1-y2)) + r)/2.0;
	rx = double(x1-x2);
	ry = double(yy1-y2);
	rx = rr/sqrt((x1-x2)*(x1-x2)+(yy1-y2)*(yy1-y2))*rx + x2*1.0;
	ry= rr/sqrt((x1-x2)*(x1-x2)+(yy1-y2)*(yy1-y2))*ry + y2*1.0;
	printf("%0.10lf %0.10lf %0.10lf\n",rx,ry,rr);
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值