Points on Cycle
Time Limit: 1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64u
Description
There is a cycle with its center on the origin.
Now give your a point in the cycle, you is to find out the and points on it, to maximize the sum of the distance bet Ween each other
Assume that radius of the cycle would not exceed 1000.
Input
There is T test cases, in each case there is 2 decimal number representing the coordinate of the given point.
Output
For each testcase is supposed to output the coordinates of both of the Unknow points by 3 decimal places of precision
Alway output The lower one first (with a smaller y-coordinate value), if they has the same Y value output the one with a s Maller X.
NOTEWhen output, if the absolute difference between the coordinate values X1 and X2 is smaller than 0.0005, we assume they are Equal.
Sample Input
21.500 2.000563.585 1.251
Sample Output
0.982-2.299-2.482 0.299-280.709-488.704-282.876 487.453
Problem Analysis: It is a geometric problem, assuming that the point a coordinates (X0,Y0), the location point B,c (X1,y1), (X2,y2). The circle equation is x2+y2 = r2; The circle equation can be transformed into x=rcosα,y=rsinα;
and x12+y1 2= r2 = x02+y0 2, (a*b)/| a|*| B| = cos120.
Easy to get acosα+ bsinα= -0.5r
(acosα) 2 = (0.5r + bsinα) 2
r2sinα2 + rbsinα+ 0.25r2-a2 = 0
X1 = -0.5*b + a*√3 * 0.5 or x1 = -0.5*b-a*√3 *0.5 (shed)
and y = -0.5*b-a*√3 * 0.5 or y= 0.5*b + a*√3 * 0.5 (Shed)
The same can be done by x2, y2;
It can also be solved directly using the cos (α + β) = cosαcosβ-Sinαsinβ,sin (α + β) = sinαcosβ+ cosαsinβ
1#include <cstdio>2#include <cmath>3 intMain ()4 {5 DoubleA,b,x0,y0,x1,y1,x2,y2;6 intT;7A=SQRT (3.0)/2;8b=-0.5;9scanf"%d",&t);Ten while(t--) One { Ascanf"%LF%LF",&x0,&y0); -X1 = b*x0-a*y0; -Y1 = b*y0 + A *x0; thex2 = b*x0 + A *y0; -y2 = b*y0-a*x0; - if(Y1<y2 | | ((Fabs (Y1-y2) <0.005) && X1 <x2)) -printf"%.3lf%.3lf%.3lf%.3lf\n", x1,y1,x2,y2); + Else -printf"%.3lf%.3lf%.3lf%.3lf\n", x2,y2,x1,y1); + } A return 0; at}
View Code
Summer Camp (2) Eighth bounce-----Points on Cycle (hdu1700)