HDU 1700 Points on Cycle(向量旋转)

题目链接

水题,卡了下下精度。

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cmath>
 4 using namespace std ;
 5 #define PI acos(-1.0)
 6 #define eps 1e-8
 7 int judge(double x,double y)
 8 {
 9     double a;
10     a = x-y;
11     if(a < 0)
12         a = -a;
13     if(a < eps)
14         return 1;
15     else
16         return 0;
17 }
18 int main()
19 {
20     double x,y,lx,rx,ly,ry,a;
21     int t;
22     scanf("%d",&t);
23     while(t--)
24     {
25         scanf("%lf%lf",&x,&y);
26         a = PI/180*120;
27         lx=x*cos(a)-y*sin(a);
28         ly=x*sin(a)+y*cos(a);
29         rx=x*cos(a)+y*sin(a);
30         ry=-x*sin(a)+y*cos(a);
31         if(ly - ry > eps)
32         {
33             swap(ly,ry);
34             swap(lx,rx);
35         }
36         else if(judge(ly,ry))
37         {
38             if(lx - rx > eps)
39             {
40                 swap(ly,ry);
41                 swap(lx,rx);
42             }
43         }
44         printf("%.3lf %.3lf %.3lf %.3lf
",lx,ly,rx,ry);
45     }
46     return 0;
47 }
原文地址:https://www.cnblogs.com/naix-x/p/3376618.html