HDU4998 Rotate (2014 ACM/ICPC Asia Regional Anshan Online)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4998

题意:给定n个点 和n个角度 ,平面内一个点分别以这个点Point(i)为旋转中心 逆时针旋转 R(i)度

求最后相当于绕那个点旋转多少度 求这个点的坐标 以及旋转的角度

一点(x,y)绕一个点(x0,y0)旋转 r0 度的公式为

x1= (x - x0)*cos(r0) - (y - y0)*sin(r0)  + x0 ;
y1= (x - x0)*sin(r0) + (y - y0)*cos(r0) + y0 ;

最后旋转点肯定是最后这两条由(xs1,ys1) (xs2,xs2) 组成的直线 以及 由(xe1,ye1) (xe2,xe2) 垂直平分线的交点,ansr = (r1+r2+.....+rn)%(2*pi);

代码如下:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

const double pi = acos(-1.0);

struct point{
    double x,y;
};

point calu(point a,point b,double r)
{
    point c;
    c.x = (a.x - b.x) * cos(r) - (a.y - b.y) * sin(r) + b.x;
    c.y = (a.x - b.x) * sin(r) + (a.y - b.y) * cos(r) + b.y;
    return c;
}

int main()
{
    int n,t;
    scanf("%d",&t);
    while(t--){
        point a,b,c,d;
        double r,ansr;
        scanf("%d",&n);
        a.x=a.y=0;
        b.x=b.y=1;
        ansr=0;
        for(int i=0;i<n;i++){
            scanf("%lf%lf%lf",&c.x,&c.y,&r);
            ansr+=r;
            if(ansr>=2*pi)
                ansr-=2*pi;
            a=calu(a,c,r);
            b=calu(b,c,r);
        }
        double t1 = (a.x*a.x+a.y*a.y)*(2*b.y-2)-2*a.y*(b.x*b.x+b.y*b.y)+4*a.y;
        double t2 = 4*a.y-4*a.y*b.x+4*a.x*b.y-4*a.x;
        double x = t1/t2;
        double t3 = (a.x*a.x+a.y*a.y)-2*x*a.x;
        double t4 = 2*a.y;
        double y = t3/t4;
        printf("%lf %lf %lf\n",x,y,ansr);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值