UVA_12300_SmallestRegularPolygon

12300 - Smallest Regular Polygon

Time limit: 1.000 seconds


Given two different points A and B, your task is to nd a regular polygon of n sides, passing through
these two points, so that the polygon area is minimized.
Input
There will be at most 100 test cases. Each case contains 5 integers xA, yA, xB, yB, n (0 xA; yA; xB; yB
100, 3 n 10000), the coordinates of A and B, and the number of sides of the regular polygon. The
two points A and B are always different. The last test case is followed by a line with ve zeros, which
should not be processed.
Output
For each test case, print the smallest area of the regular polygon to six decimal places.
Sample Input
0 0 1 1 4
1 2 3 4 5
2 3 4 5 6
0 0 0 0 0
Sample Output
1.000000
5.257311
5.196152


题目的意思就是说给你两个点

然后让你求一个最小的正n边形

能包住这两个点

问题问的是这个正多边形的面积


这里有两种情况 n为奇数

那么显然一个多边形最远的两个点为一个顶点到对着的边的距离

n为偶数

最远两点就是两个对着的顶点

然后由多边形中心可以把多边形划分成三角形 

进一步通过几何关系和三角函数求出多边形的边长


#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

const double PI=acos(-1.0);

int main()
{
    int xa,ya,xb,yb,n;
    while(scanf("%d%d%d%d%d",&xa,&ya,&xb,&yb,&n)!=EOF)
    {
        if(!xa&&!xb&&!ya&&!yb&&!n)
            break;
        double d=sqrt((double)(xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
        double sita=PI/n;
        if(n%2)
        {
            double r=d/2/cos(sita/2);
            double l=2*r*sin(sita);//多边形的边长
            double dl=r*cos(sita); //边心距
            printf("%.6lf\n",l*dl/2*n);
        }
        else
        {
            double l=2*d/2*sin(sita);//多边形的边长
            double dl=d/2*cos(sita); //边心距
            printf("%.6lf\n",l*dl/2*n);
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值