HDU 4998 Rotate

Rotate

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1116    Accepted Submission(s): 503
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 :).
 

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π.
 

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.
 

Sample Input
  
  
1 3 0 0 1 1 1 1 2 2 1
 

Sample Output
  
  
1.8088715944 0.1911284056 3.0000000000
 

Source
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5751  5750  5749  5748  5747 

 


计算几何,有一个点,绕着另一个点旋转了p角度。并且旋转了n次。问最初这个点等价于绕哪个点旋转n角度和那个等价。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define N 100050
typedef long long ll;
const int MOD = 1e9+7;
#define PI acos(-1)
int  main()
{
    double start_x, start_y;
    double final_x, final_y;
    double x, y, p;
    double  final_jiao, xx, yy;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        start_x=start_y=xx=yy=1;  //随便设立
        final_jiao=0;
        while(n--)
        {
            scanf("%lf %lf %lf",&x,&y,&p);
            final_jiao+=p;
            if(final_jiao>=2*PI)
                final_jiao-=2*PI;
            final_x=(xx-x)*cos(p)-(yy-y)*sin(p)+x;    // x0= (x - xx)*cos(a) - (y - yy)*sin(a) + xx ;  设x,y绕着点xx,yy转了p角度。则x0,y0为新的点。
            final_y=(xx-x)*sin(p)+(yy-y)*cos(p)+y;   //  y0= (x - xx)*sin(a) + (y - yy)*cos(a) + yy ;
            xx=final_x;
            yy=final_y;
        }
        // 换下公式,相当于在一开始的点然后找一个点旋转使得最后的点为fianl_x,final_y  //则可以推出
        x=((final_x-start_x*cos(final_jiao)+start_y*sin(final_jiao))*(1-cos(final_jiao))-(final_y-start_x*sin(final_jiao)-start_y*cos(final_jiao))*sin(final_jiao))/(2-2*cos(final_jiao));
        y=((final_x-start_x*cos(final_jiao)+start_y*sin(final_jiao))*(1-cos(final_jiao))-(1-cos(final_jiao))*(1-cos(final_jiao))*x)/((1-cos(final_jiao))*sin(final_jiao));
        printf("%.12lf %.12lf %.12lf\n",x,y,final_jiao);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值