HDU - 1700(计算几何)

该博客探讨了如何在给定圆心位于原点的圆上找到两点,以使这两点之间的距离之和最大。问题描述指出,已知圆的半径不超过1000,并给出了一个圆上的特定点的坐标。博主通过分析指出,解决这个问题的关键在于理解在边数固定的情况下,圆的内接正多边形的周长最长。他们还提供了二维矢量旋转的公式,并给出了相应的代码实现。

问题描述:

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. 

NOTE
when output, if the absolute difference between the coordinate values X1 and X2 is smaller than 0.0005, we assume they are equal.

Sample Input

2
1.500 2.000
563.585 1.251
Sample Output

0.982 -2.299 -2.482 0.299
-280.709 -488.704 -282.876 487.453


题目题意:题目给我们一个点的坐标,这个点在一个以原点0为圆心的圆上,求这个圆上的另外俩个点的坐标使得这个三角形的周长最长.

题目分析:考的主要是这个知识点:(边数一定)圆的内接正多边形的周长最长,我试图证了一下,发现数学知识不够用了,等找个机会问问高数老师(再补回来).

还有就是这是这个矢量旋转公式:

二维矢量旋转公式:点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;
}









评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值