HDU 4998 Rotate (computing ry), Anshan division network competition, 2014, hdu4998
RotateTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Special Judge
Problem DescriptionNoting is more interesting than rotation!
Your little sister likes to rotate things. to put it easier to analyze, your sister makes n rotations. in the I-th time, she makes everything in the plane rotate counter-clockwisely around a point ai by a radian of pi.
Now she promises that the total effect of her rotations is a single rotation around a point A by radian P (this means the sum of pi is not a multiplier of 2 π ).
Of course, you shocould be able to figure out what is A and P :).
InputThe first line contains an integer T, denoting the number of the test cases.
For each test case, the first line contains an integer n denoting the number of the rotations. then n lines follows, each containing 3 real numbers x, y and p, which means rotating around point (x, y) counter-clockwisely by a radian of p.
We promise that the sum of all p's is differed at least 0.1 from the nearest multiplier of 2 π.
T <= 100. 1 <= n <= 10. 0 <= x, y <= 100. 0 <= p <= 2 π.
OutputFor each test case, print 3 real numbers x, y, p, indicating that the overall rotation is round (x, y) counter-clockwisely by a radian of p. note that you shoshould print p where 0 <= p <2 π.
Your answer will be considered correct if and only if for x, y and p, the absolute error is no larger than 1e-5.
Sample Input
130 0 11 1 12 2 1
Sample Output
1.8088715944 0.1911284056 3.0000000000
Source2014 ACM/ICPC Asia Regional Anshan Online
I wrote this question for a few hours during the competition, but it was still too weak.
Meaning: an object rotates around a point at a time. After being rotated for n times, it is equivalent to directly reaching the final state after rotating a certain angle around a point in the starting state. Calculate the coordinates and Rotation Angle of the point.
Analysis: because the number of rotations is small, the rotation process can be directly simulated. Select two points as the starting state, find the coordinates corresponding to the two points after rotation, connect the corresponding points before and after rotation, find the intersection of the two lines, and then find the rotation angle.
# Include <cstdio> # include <cmath> using namespace std; # define PI acos (-1.0) struct Point {double x, y; Point (double x = 0, double y = 0): x (x), y (y) {}}; int n; Point p [15]; // rotating Point double rad [15]; // Rotation Angle typedef Point Vector; Vector operator + (Vector A, Vector B) {return Vector (. x + B. x,. y + B. y);} Vector operator-(Point A, Point B) {return Vector (. x-B. x,. y-B. y);} Vector operator * (Vector, Double p) {return Vector (. x * p,. y * p);} Vector operator/(Vector A, double p) {return Vector (. x/p,. y/p);} bool operator <(const Point & a, const Point & B) {return. x <B. x | (. x = B. x &. y <B. y);} const double eps = 1e-10; int dcmp (double x) {if (fabs (x) <eps) return 0; else return x <0? -1: 1;} bool operator = (const Point & a, const Point & B) {return dcmp (. x-B. x) = 0 & dcmp (. y-B. y) = 0;} double Dot (Vector A, Vector B) {return. x * B. x +. y * B. y;} // Dot product double Length (Vector A) {return sqrt (Dot (A, A);} // evaluate the model of the Vector double Angle (Vector A, Vector B) {return acos (Dot (A, B)/Length (A)/Length (B);} // calculates the angle double Cross (Vector A, Vector B) between two vectors) {return. x * B. y-. y * B. x;} // cross-multiplication Vector Rotate (Vector A, double rad) {// returns Vector (. x * cos (rad)-. y * sin (rad),. x * sin (rad) +. y * cos (rad);} Vector Normal (Vector A) {// evaluate the Normal Vector of Vector A, double L = Length (A); return Vector (-. y/L,. x/L);} Point GetLineIntersection (Point P, Vector v, Point Q, Vector w) {// returns the intersection of a straight line Vector u = P-Q; double t = Cross (w, u)/Cross (v, w); return P + v * t;} Vector Rotate_Point (Vector A) {for (int I = 0; I <n; I ++) {A = p [I] + Rotate (A-p [I], rad [I]); // convert to Vector rotation} return A;} Vector Get_Mid_Point (Point A, Point B) {// calculate the midpoint return Vector (. x + B. x)/2, (. y + B. y)/2);} void Get_Ans () {Point f1 [2], f2 [2], mid [2], vec [2]; f1 [0]. x =-1; f1 [0]. y =-1; f1 [1]. x =-10; f1 [1]. y =-50; for (int I = 0; I <2; I ++) {f2 [I] = Rotate_Point (f1 [I]); mid [I] = Get_Mid_Point (f1 [I], f2 [I]); vec [I] = Normal (f1 [I]-f2 [I]);} point ans = GetLineIntersection (mid [0], vec [0], mid [1], vec [1]); double ansp = Angle (f1 [0]-ans, f2 [0]-ans); if (Cross (f1 [0]-ans, f2 [0]-ans) <0) ansp = 2 * PI-ansp; if (dcmp (ans. x) = 0) ans. x = 0; if (dcmp (ans. y) = 0) ans. y = 0; printf ("%. 10lf %. 10lf %. 10lf \ n ", ans. x, ans. y, ansp) ;}int main () {int T; scanf ("% d", & T); while (T --) {scanf ("% d ", & n); for (int I = 0; I <n; I ++) {scanf ("% lf", & p [I]. x, & p [I]. y, & rad [I]); if (dcmp (rad [I]-2 * PI) = 0 | dcmp (rad [I]) = 0) {rad [I] = 0; n --; I -- ;}} Get_Ans ();} return 0 ;}