HDU 4998 Rotate

举报
Linux猿 发表于 2021/08/04 23:00:30 2021/08/04
【摘要】 题目链接~~> 做题感悟:表示自己太弱了,模拟也没模拟出来,简单想法也没想到,而且是一大堆人在讨论。 解题思路:                   平面每次绕一个点旋转,最终平面旋转的角度就是所有旋转的角度之和,这样你只需要设置一个起始点 x0 ,y0 ,在经过变换后变为 ...

题目链接~~>

做题感悟:表示自己太弱了,模拟也没模拟出来,简单想法也没想到,而且是一大堆人在讨论。

解题思路:

                  平面每次绕一个点旋转,最终平面旋转的角度就是所有旋转的角度之和,这样你只需要设置一个起始点 x0 ,y0 ,在经过变换后变为 x1 ,y1 ,因为角度已经知道这样可以用坐标旋转的方程解出目标点( x  , y )

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

               y1  = ( x0 - x ) * sin( a )  +  ( y0 - y1 ) * sin( a )  + y  ;

解二元一次方程即可。

代码:


  
  1. #include<iostream>
  2. #include<sstream>
  3. #include<map>
  4. #include<cmath>
  5. #include<fstream>
  6. #include<queue>
  7. #include<vector>
  8. #include<sstream>
  9. #include<cstring>
  10. #include<cstdio>
  11. #include<stack>
  12. #include<bitset>
  13. #include<ctime>
  14. #include<string>
  15. #include<iomanip>
  16. #include<algorithm>
  17. using namespace std ;
  18. #define INT long long int
  19. const int INF = 99999999 ;
  20. const double esp = 0.00000001 ;
  21. const double PI = acos(-1.0) ;
  22. const int MP = 2000000 + 5 ;
  23. const int MY = 200000 + 5 ;
  24. const int MX = 10000 + 5 ;
  25. int n ;
  26. struct Point
  27. {
  28. double x ,y ;
  29. } ;
  30. int main()
  31. {
  32. //freopen("input.txt" ,"w" ,stdout) ;
  33. int Tx ;
  34. scanf("%d" ,&Tx) ;
  35. while(Tx--)
  36. {
  37. scanf("%d" ,&n) ;
  38. double P = 0 ,x0 = 0 ,y0 = 0 ,xa ,ya ,pi ,x ,y ;
  39. for(int i = 0 ;i < n ; ++i)
  40. {
  41. scanf("%lf%lf%lf" ,&x ,&y ,&pi) ;
  42. P += pi ;
  43. if(P >= 2.0*PI)
  44. P -= 2.0*PI ;
  45. xa = (x0 - x)*cos(pi) - (y0 - y)*sin(pi) + x ;
  46. ya = (x0 - x)*sin(pi) + (y0 - y)*cos(pi) + y ;
  47. x0 = xa ;
  48. y0 = ya ;
  49. }
  50. double PX = (x0*(1-cos(P))-y0*sin(P))/(2.0-2.0*cos(P)) ;
  51. double PY = (x0+PX*cos(P)-PX)/sin(P) ;
  52. cout<<fixed<<setprecision(10)<<PX<<" "<<PY<<" "<<P<<endl ;
  53. }
  54. return 0 ;
  55. }


文章来源: blog.csdn.net,作者:Linux猿,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/nyist_zxp/article/details/39429265

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。