Codeforces Round #465 (Div. 2) C. Fifa and Fafa
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.
The single line of the input contains 5 space-separated integers R, x1, y1, x2, y2 (1 ≤ R ≤ 105, |x1|, |y1|, |x2|, |y2| ≤ 105).
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.
5 3 3 1 1
3.7677669529663684 3.7677669529663684 3.914213562373095
10 5 5 5 15
5.0 5.0 10.0
几何题
题意大概是说给你 圆心O和半径R 还有一个点a 在圆O内求 另一个圆x 的圆心和半径 要求圆x不能包含a(a可以在边界上)
当点在圆外时,输出圆心和半径即可
当点和圆心重合时,输出 (x0 + 1/2*R),y,R 即可
其余情况时,如图
B为圆心,A为给出的点,从A出发过B作射线交圆B为F点 那么所求点就是AF的中点 所求半径就是AE长
圆心的求法
(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();
}
}
推荐阅读
-
Codeforces Round #320 (Div. 2) C. A Problem about Polyline ( 数学 )
-
Codeforces Round #654 (Div. 2)-C. A Cookie for You
-
Educational Codeforces Round 85 (Rated for Div. 2) C. Circle of Monsters(前缀和 预处理 贪心)
-
Codeforces Round #651 (Div. 2) C. Number Game
-
Codeforces Round #668 (Div. 2)-C. Balanced Bitstring
-
Educational Codeforces Round 99 (Rated for Div. 2) C. Ping-pong
-
Codeforces Round #256 (Div. 2) C. Painting Fence(分治贪心)_html/css_WEB-ITnose
-
Codeforces Round #277 (Div. 2)-C. Palindrome Transformation (贪心)_html/css_WEB-ITnose
-
Codeforces Round #277 (Div. 2)-C. Palindrome Transformation (贪心)_html/css_WEB-ITnose
-
C. Mortal Kombat Tower(动态规划)Educational Codeforces Round 95 (Rated for Div. 2)