问题描述:
There is a cycle with its center on the origin.
Now give you a point on the cycle, you are to find out the other two points on it, to maximize the sum of the distance between each other
you may assume that the radius of the cycle will not exceed 1000.
Input
There are T test cases, in each case there are 2 decimal number representing the coordinate of the given point.
Output
For each testcase you are supposed to output the coordinates of both of the unknow points by 3 decimal places of precision
Alway output the lower one first(with a smaller Y-coordinate value), if they have the same Y value output the one with a smaller X.
Sample Input
2 1.500 2.000 563.585 1.251Sample Output
0.982 -2.299 -2.482 0.299 -280.709 -488.704 -282.876 487.453
题目分析:考的主要是这个知识点:(边数一定)圆的内接正多边形的周长最长,我试图证了一下,发现数学知识不够用了,等找个机会问问高数老师(再补回来).
还有就是这是这个矢量旋转公式:
二维矢量旋转公式:点p(x1,y1) 绕点0(x0,y0)旋转r角度d(顺时针)的坐标
X=(x1-x0)*cos(r)-(y1-y0)*sin(r)+x0;
Y=(x1-x0)*sin(r)+(y1-y0)*cos(r)+y0;
代码如下:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const double epx=5*1e-4;
const double PI=acos(-1.0);
int main()
{
int t;
scanf("%d",&t);
while (t--) {
double x,y;
scanf("%lf%lf",&x,&y);
double r=2*PI/3;
double x1=x*cos(r)-y*sin(r);
double y1=x*sin(r)+y*cos(r);
double x2=x*cos(2*r)-y*sin(2*r);
double y2=x*sin(2*r)+y*cos(2*r);
if (y2-y1>epx) {//注意细节,绝对值小于epx就是相等的了
printf("%.3lf %.3lf %.3lf %.3lf\n",x1,y1,x2,y2);
}
else if (fabs(y1-y2)<epx) {
if (x1<x2)
printf("%.3lf %.3lf %.3lf %.3lf\n",x1,y1,x2,y2);
else
printf("%.3lf %.3lf %.3lf %.3lf\n",x2,y2,x1,y1);
}
else
printf("%.3lf %.3lf %.3lf %.3lf\n",x2,y2,x1,y1);
}
return 0;
}
该博客探讨了如何在给定圆心位于原点的圆上找到两点,以使这两点之间的距离之和最大。问题描述指出,已知圆的半径不超过1000,并给出了一个圆上的特定点的坐标。博主通过分析指出,解决这个问题的关键在于理解在边数固定的情况下,圆的内接正多边形的周长最长。他们还提供了二维矢量旋转的公式,并给出了相应的代码实现。
394

被折叠的 条评论
为什么被折叠?



