HDU1700->向量旋转
题意:
一个圆的圆心在(0,0),已知圆上一点,求另外两点使得这三点构成的圆内接三角形周长最大。
题解:
圆的内接三角形中,周长最大的为正三角形。
已知一点即知道了圆的半径,和一个圆心与该点构成的向量,旋转这个向量即可得到另外两个点。
代码:
#include <stdio.h>
#include <iostream>
#include <cmath>
using namespace std ;
#define PI acos(-1.0)
struct Point
{
double x , y ;
Point(){}
Point(double _x , double _y)
{
x = _x ; y = _y ;
}
bool operator < (const Point &other)
{
return y < other.y || (y == other.y && x < other.x) ;
}
};
Point rotate(Point A , double rad)
{
return Point(A.x * cos(rad) - A.y * sin(rad) , A.y * cos(rad) + A.x *sin(rad)) ;
}
Point p[3] ;
int main()
{
int T ;
scanf("%d" , &T) ;
while(T --)
{
scanf("%lf%lf" , &p[0].x , &p[0].y) ;
p[1] = rotate(p[0] , PI * 2 / 3) ;
p[2] = rotate(p[0] , -PI * 2 / 3) ;
Point a , b ;
if(p[1] < p[2]) a = p[1] , b = p[2] ;
else a = p[2] , b = p[1] ;
printf("%.3f %.3f %.3f %.3f\n" , a.x , a.y , b.x , b.y) ;
}
return 0 ;
}