Smallest Regular Polygon - UVa 12300 几何

39 篇文章 0 订阅

Smallest Regular Polygon

Given two different points A and B, your task is to find 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 five 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

Output for the Sample Input

1.000000
5.257311
5.196152

题意:给定两个点,求经过这两个点的正n边形的最小面积。

思路:n为偶数,那么就是对角线最长,n为奇数时,相对最远点的斜对角线最长。

AC代码如下:

#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
double eps=1e-8;
int main()
{
    int n;
    double x1,x2,y1,y2,d,r,p,S;
    while(~scanf("%lf%lf%lf%lf%d",&x1,&y1,&x2,&y2,&n) && n>0)
    {
        d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))/2;
        if(n&1)
        {
            p=M_PI*2*(n-1)/(2*n)/2;
            r=d/sin(p);
        }
        else
          r=d;
        p=2*M_PI/n;
        S=r*r*sin(p)/2*n;
        printf("%.6f\n",S);
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值