HDU 6097 --- Mindis (Binary), hdu6097 --- mindis
Question Link
Problem DescriptionThe center coordinate of the circle C is O, the coordinate of O is (0, 0), and the radius is r.
P and Q are two points not outside the circle, and PO = QO.
You need to find a point D on the circle, which makes PD + QD minimum.
Output minimum distance sum.
InputThe first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with r: the radius of the circle C.
Next two line each line contains two integers x, y denotes the coordinate of P and Q.
Limits
T ≤ 500000
− 100 ≤ x, y ≤ 100
1 ≤ r ≤100
OutputFor each case output one line denotes the answer.
The answer will be checked correct if its absolute or relative error doesn' t exceed 10 −6.
Formally, let your answer be a, and the jury's answer be B. Your answer is considered correct if | a −b | max (1, B) ≤ 10 −6.
Sample Input444 00 4 40 33 040 22 040 11 0
Sample Output5.65685435.65685435.89213306.7359174: There is a circle with the center at the origin, input the radius r, and there are two points in the Circle P. Q has the same distance from the center. Now, find a M on the circle, minimum PM + QM? Train of Thought: for the two vertices P and Q in the circle, if they are used as the two focal points of the elliptic, we can see from figure 1: When the vertex of the elliptic is tangent to the circle, the circle has three focal points, and the distance from the point to P and Q on the elliptic is a fixed value. Then we can narrow down the ellipse. Next we will have four intersections and continue to narrow down the elliptic. We can see in Figure 2 that there are only two intersections between the elliptic and the circle, because the distance from the point outside the elliptic to the two focal points is greater than 2a, the distance between the point on the elliptic and the two focal points is 2a ,. In Figure 2, except for the two intersections, all the vertices on the circle are located outside the elliptic. Therefore, the distance from the intersection to the P and Q points is the minimum and equal to 2a. How can we find the tangent elliptic? Binary solution. Specific: from the two focal points P and Q, we can determine c = PQ/2. Now, if we give another B value, we can determine this elliptic, and the larger the B value, the larger the elliptic, the smaller the value of B, the smaller the oval, so we need to find the B value of 2 when there are only two focal points in the tangent, so we need to find the minimum B when the circle and the elliptical intersection. We can find the h and R-h shown in figure 3, then the elliptic equation is: x ^ 2/a ^ 2 + (y-h) ^ 2/B ^ 2 = 1 (this equation is generated when PQ is parallel to the X axis, but PQ is not affected when it is not even X. We just use it to determine whether it is related to the circle) circle: x ^ 2 + y ^ 2 = R ^ R, and B> 0 (apparently), B <R-h, so in (0, R-h) search for B in binary mode. The Code is as follows:
# Include <iostream> # include <stdio. h> # include <math. h> # include <algorithm> using namespace std; const double eps = 1e-10; double dis (double x1, double y1, double x2, double y2) {return sqrt (x2-x1) * (x2-x1) + (y2-y1) * (y2-y1);} namespace IO {const int MX = 4e7; // 1e7 memory occupied 11000kb char buf [MX]; int c, sz; void begin () {c = 0; sz = fread (buf, 1, MX, stdin);} inline bool read (int & t) {while (c <sz & buf [c]! = '-' & (Buf [c] <'0' | buf [c]> '9') c ++; if (c> = sz) return false; bool flag = 0; if (buf [c] = '-') flag = 1, c ++; for (t = 0; c <sz & '0' <= buf [c] & buf [c] <= '9'; c ++) t = t * 10 + buf [c]-'0'; if (flag) t =-t; return true ;}} int main () {IO :: begin (); int T; double R, x1, x2, y1, y2; double x3, y3; double A, B, C, dt, ans1, ans2; // cin> T; IO: read (T); while (T --) {// scanf ("% lf ", & R, & x1, & y1, & x2, & y2); int xr, xx1, xx2, yy1, yy2; IO: read (xr); IO :: read (xx1); IO: read (yy1); IO: read (xx2); IO: read (yy2); R = xr; x1 = xx1; y1 = yy1; x2 = xx2; y2 = yy2; double c = dis (x1, y1, x2, y2) * 0.5; c = c * c; x3 = (x1 + x2) * 0.5; y3 = (y1 + y2) * 0.5; double h = dis (x3, y3, 0.0, 0.0 ); // cout