Rotate+hud+2014鞍山网络赛

来源:互联网 发布:改后台淘宝会查吗 编辑:程序博客网 时间:2024/04/28 16:22

Rotate

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 96    Accepted Submission(s): 48
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
130 0 11 1 12 2 1
 

Sample Output
1.8088715944 0.1911284056 3.0000000000
解决方案:这题被坑了,就是高中数学没学好。当某点逆时针旋转过180度时,要注意如果求的是弦与半径组成的三角形的顶角,这是顺时针的旋转的角,要转成逆时针的角。
code:
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;const double pi=3.14159265358979323846;double dist(double x1,double y1,double x2,double y2){    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+1e-8);}void rot(double x0,double y0,double p,double oldx,double oldy,double *newx,double *newy){    double d=dist(x0,y0,oldx,oldy);    *newx=x0+(oldx-x0)*cos(p)-(oldy-y0)*sin(p);    *newy=y0+(oldy-y0)*cos(p)+(oldx-x0)*sin(p);}int main(){    int t;    scanf("%d",&t);    while(t--)    {        int n;        scanf("%d",&n);        double x0,y0,p,px=0.0;        bool flag=false;        double prex=-1.0,prey=-1.0;        double oldx1=110.0,oldy1=110.0,oldx2=120.0,oldy2=120.0;        double newx1=110.0,newy1=110.0,newx2=120.0,newy2=120.0;        for(int i=0; i<n; i++)        {            scanf("%lf%lf%lf",&x0,&y0,&p);            if(prex<0&&prey<0)            {                prex=x0,prey=y0;            }            else            {                if(fabs(prex-x0)>=1e-8||fabs(prey-y0)>=1e-8)                {                    flag=true;                }            }            px+=p;            if(px-2*pi>1e-8) px-=2*pi;            rot(x0,y0,p,oldx1,oldy1,&newx1,&newy1);            oldx1=newx1,oldy1=newy1;            rot(x0,y0,p,oldx2,oldy2,&newx2,&newy2);            oldx2=newx2,oldy2=newy2;        }        if(n==1||!flag)        {            printf("%.10lf %.10lf %.10lf\n",x0,y0,px);            continue;        }        double a=(oldx1*oldx1+oldy1*oldy1-110*110-110*110)/(110-oldy1);        double b=(-oldx2*oldx2-oldy2*oldy2+120*120+120*120)/(120-oldy2);        double c=2*((oldx1-110)/(-oldy1+110)-(oldx2-120)/(-oldy2+120));        double x=(a+b)/c;        double a1=(oldx1*oldx1+oldy1*oldy1-110*110-110*110)/(-110+oldx1);        double b1=(oldx2*oldx2+oldy2*oldy2-120*120-120*120)/(-120+oldx2);        double c1=2*((oldy1-110)/(oldx1-110)-(oldy2-120)/(oldx2-120));        double y=(a1-b1)/c1;        double d1=dist(oldx1,oldy1,110,110)/2.0;        double d2=dist(oldx1,oldy1,x,y);        double p1=2*asin(d1/d2);        double xx;        double yy;        rot(x,y,p1,110,110,&xx,&yy);///判断求出的角度是否为顺时针所转的角        if(fabs(xx-oldx1)<=1e-8&&fabs(yy-oldy1)<=1e-8){            printf("%.10lf %.10lf %.10lf\n",x,y,p1);        }        else{            p1=2*pi-p1;            printf("%.10lf %.10lf %.10lf\n",x,y,p1);        }        //if(oldx1)    }    return 0;}

0 0
原创粉丝点击