HDU 4998 Rotate,hdu4998rotate

來源:互聯網
上載者:User

HDU 4998 Rotate,hdu4998rotate
RotateTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 210    Accepted Submission(s): 110



Problem DescriptionNoting 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 :).
 
InputThe 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π. 
OutputFor 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
 
Source2014 ACM/ICPC Asia Regional Anshan Online


題目連結 :http://acm.hdu.edu.cn/showproblem.php?pid=4998

題目大意 :某個平面繞每個點逆時針旋轉一個弧度值,將該過程等效為該平面繞著一個點逆時針旋轉一個弧度值,求出等效點的座標和旋轉弧度值。

題目分析 :任意取兩個點通過一組旋轉得到另外兩個對應的點,再求對應直線的垂直平分線交於一點,該點就是所要求的點的座標,弧度考慮可以用反三角函數求出,這裡需要注意一個問題,比賽時wa到死,就是旋轉的方向問題,這裡可以用向量的差乘來處理

代碼 :
#include <cstdio>#include <cstring>#include <cmath>#define PI 4.0 * atan(1.0)using namespace std;struct Move{       double x, y, p;}move[15];int n;double Dist(double x1, double y1, double x2, double y2)  //求兩點間距離{    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));}double calx(double x, double y)  //求逆時針旋轉後的x座標{    double x1, y1;    for(int i = 0; i < n; i++)    {        x1 = (x - move[i].x) * cos(move[i].p) - (y - move[i].y) * sin(move[i].p) + move[i].x;        y1 = (x - move[i].x) * sin(move[i].p) + (y - move[i].y) * cos(move[i].p) + move[i].y;        x = x1;        y = y1;    }    return x1;}double caly(double x, double y)  //求逆時針旋轉後的y座標{    double x1, y1;    for(int i = 0; i < n; i++)    {        x1 = (x - move[i].x) * cos(move[i].p) - (y - move[i].y) * sin(move[i].p) + move[i].x;        y1 = (x - move[i].x) * sin(move[i].p) + (y - move[i].y) * cos(move[i].p) + move[i].y;        x = x1;        y = y1;    }    return y1;}int main(){    int ca;    scanf("%d", &ca);    while(ca--)    {        scanf("%d", &n);        for(int i = 0; i < n; i++)            scanf("%lf %lf %lf", &move[i].x, &move[i].y, &move[i].p);        //任意取兩個點        double x1 = 34.11111111;        double y1 = 1.4211111111;        double x3 = 42.3111111111;        double y3 = 2.32111111111;        //求出這兩個點逆時針旋轉後的兩個點        double x2 = calx(x1, y1);        double y2 = caly(x1, y1);        double x4 = calx(x3, y3);        double y4 = caly(x3, y3);        //通過y = kx + b;聯立解得兩垂直平分線的交點        double x = ((y1 + y2 - y3 - y4) * (y1 - y2) * (y3 - y4) + (x4 * x4 - x3 * x3) * (y1 - y2) - (x2 * x2 - x1 * x1) * (y3 - y4))        / (2 * (x4 - x3) * (y1 - y2) - 2 * (x2 - x1) * (y3 - y4));        double y = (((x2 - x1) / (y1 - y2)) * (x - (x1 + x2) / 2) + (y1 + y2) / 2);        //圓的半徑        double r = Dist(x, y, x1, y1);        //某兩個對應點的距離        double dist = Dist(x1, y1, x2, y2);        //通過三角函數關係求出弧度        double angel = 2 * asin(dist / (2 * r));        //通過向量叉乘確定方向        double d1 = (x1 - x) * (y2 - y) - (x2 - x) * (y1 - y);        //方向判定        if(d1 < 0)            angel = 2 * PI - angel;         //精度特判        if(fabs(x) < 1e-10)            x = 0;        if(fabs(y) < 1e-10)            y = 0;        printf("%.10f %.10f %.10f\n", x, y, angel);    }}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.