欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Codeforces Round #465 (Div. 2) C. Fifa and Fafa

程序员文章站 2022-06-03 19:38:57
...
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

几何题 

题意大概是说给你 圆心O和半径R 还有一个点a 在圆O内求 另一个圆x 的圆心和半径 要求圆x不能包含a(a可以在边界上)

Codeforces Round #465 (Div. 2) C. Fifa and Fafa

当点在圆外时,输出圆心和半径即可

当点和圆心重合时,输出 (x0 + 1/2*R),y,R 即可

其余情况时,如图

Codeforces Round #465 (Div. 2) C. Fifa and Fafa

B为圆心,A为给出的点,从A出发过B作射线交圆B为F点 那么所求点就是AF的中点 所求半径就是AE长

Codeforces Round #465 (Div. 2) C. Fifa and Fafa

圆心的求法

 (xE-xA)/(xG-xA) = AE/AB     xE = (xG-xA)*AE/AB + xA

 (yE-yA)/(yG-yA) = AE/AB     yE = (xG-xA)*AE/AB + yA

JAVA代码

import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner input = new Scanner(System.in);

		double R = input.nextInt();

		double x0 = input.nextDouble();
		double y0 = input.nextDouble();
		double x1 = input.nextDouble();
		double y1 = input.nextDouble();

		double len = Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));

		double r = (len + R)/2.0;
		
		
		if(r > R) {
			System.out.println(x0 + " " + y0 + " " + R);
		}
		else if(x0 == x1 && y1 == y0) {
			System.out.println((x0+R/2.0) + " " + y0 + " " + R/2.0);
		}
		else {
			System.out.println((x1+(x0-x1)*r/len) + " " + (y1+(y0-y1)*r/len) + " " + r);
		}

		input.close();
	}

}

相关标签: 几何