首页 > 代码库 > HDU 4998
HDU 4998
Rotate
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 194 Accepted Submission(s): 101
Special Judge
Problem Description
Noting 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 should be able to figure out what is A and P :).
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 should be able to figure out what is A and P :).
Input
The 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π.
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π.
Output
For each test case, print 3 real numbers x, y, p, indicating that the overall rotation is around (x, y) counter-clockwisely by a radian of p. Note that you should 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.
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
1
3
0 0 1
1 1 1
2 2 1
Sample Output
1.8088715944 0.1911284056 3.0000000000
题目意思:
给n次操作,每次操作为x, y, p即绕点(x,y)旋转p度,经过n次旋转后 相当于绕某个固定点旋转多少度,求固定点坐标和旋转度数。
思路:
很容易发现不管怎么旋转旋转度数相加就是最终度数(>=2*PI时减去2*PI就行了),那么咱们虚拟一个起始点,然后模拟旋转操作,最后得到一个虚拟终点,又虚拟起点和虚拟终点再加上旋转度数就能算出目标坐标了。
比赛的一开始的时候这个思路就想出来了,但是我队擅长数学的那个家伙在寝室睡觉。。。无奈数学是硬伤,不知道怎么算。。后来在百度上发现了一个公式 http://jingyan.baidu.com/article/2c8c281dfbf3dd0009252a7b.html ,才把这道题搞出来。。。
由公式可以算出虚拟终点,又虚拟起点和旋转度数已知再代入那个公式中 , 两个式子算两个未知量,很好算把。。。只是敲代码时细心点,一不小心就错了。。。
代码:
#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <iostream>#include <vector>#include <queue>#include <stack>#include <cmath>using namespace std;#define PI acos(-1)main(){ double stx, sty, endx, endy, x, y, p, endp, xx, yy; int t, n, i, j, k; cin>>t; while(t--){ cin>>n; stx=sty=xx=yy=endp=0;//(stx,sty)是虚拟起点,(endx,endy)是虚拟终点 while(n--){ scanf("%lf %lf %lf",&x,&y,&p); endp+=p; if(endp>=2*PI) endp-=2*PI; endx=(xx-x)*cos(p)-(yy-y)*sin(p)+x; endy=(xx-x)*sin(p)+(yy-y)*cos(p)+y; xx=endx;yy=endy; } //再把虚拟起点和虚拟终点代入上面公式中化简就得出下面很长。。很长。。的式子了 x=((endx-stx*cos(endp)+sty*sin(endp))*(1-cos(endp))-(endy-stx*sin(endp)-sty*cos(endp))*sin(endp))/(2-2*cos(endp)); y=((endx-stx*cos(endp)+sty*sin(endp))*(1-cos(endp))-(1-cos(endp))*(1-cos(endp))*x)/((1-cos(endp))*sin(endp)); printf("%.10lf %.10lf %.10lf\n",x,y,endp); } }
HDU 4998
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。