您的位置:首页 > 其它

HDU 4998 Rotate

2014-09-20 09:34 302 查看
题目链接~~>

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

解题思路:

                  平面每次绕一个点旋转,最终平面旋转的角度就是所有旋转的角度之和,这样你只需要设置一个起始点 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  ;

解二元一次方程即可。

代码:

#include<iostream>
#include<sstream>
#include<map>
#include<cmath>
#include<fstream>
#include<queue>
#include<vector>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<stack>
#include<bitset>
#include<ctime>
#include<string>
#include<iomanip>
#include<algorithm>
using namespace std  ;
#define INT long long int
const int INF = 99999999 ;
const double esp = 0.00000001 ;
const double PI = acos(-1.0) ;
const int MP = 2000000 + 5 ;
const int MY = 200000 + 5 ;
const int MX = 10000 + 5 ;
int n ;
struct Point
{
double x ,y ;
} ;
int main()
{
//freopen("input.txt" ,"w" ,stdout) ;
int Tx ;
scanf("%d" ,&Tx) ;
while(Tx--)
{
scanf("%d" ,&n) ;
double P = 0 ,x0 = 0 ,y0 = 0 ,xa ,ya ,pi ,x ,y ;
for(int i = 0 ;i < n ; ++i)
{
scanf("%lf%lf%lf" ,&x ,&y ,&pi) ;
P += pi ;
if(P >= 2.0*PI)
P -= 2.0*PI ;
xa = (x0 - x)*cos(pi) - (y0 - y)*sin(pi) + x ;
ya = (x0 - x)*sin(pi) + (y0 - y)*cos(pi) + y ;
x0 = xa ;
y0 = ya ;
}
double PX = (x0*(1-cos(P))-y0*sin(P))/(2.0-2.0*cos(P)) ;
double PY = (x0+PX*cos(P)-PX)/sin(P) ;
cout<<fixed<<setprecision(10)<<PX<<" "<<PY<<" "<<P<<endl ;
}
return 0 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: