HDOJ 5563 Clarke and five-pointed star(枚举)

本文介绍了一种通过判断五个点是否能构成一个正五角星的算法。该算法通过枚举点的所有排列并检查每组排列中五条相邻边及五条对角线长度是否一致来实现。适用于精度要求为10^-4的几何问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



Clarke and five-pointed star

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 154    Accepted Submission(s): 87


Problem Description
Clarke is a patient with multiple personality disorder. One day, Clarke turned into a learner of geometric.
When he did a research with polygons, he found he has to judge if the polygon is a five-pointed star at many times. There are 5 points on a plane, he wants to know if a five-pointed star existed with 5 points given.
 

Input
The first line contains an integerT(1T10), the number of the test cases.
For each test case, 5 lines follow. Each line contains 2 real numbers
xi,yi(109xi,yi109), denoting the coordinate of this point.
 

Output
Two numbers are equal if and only if the difference between them is less than104.
For each test case, print
Yes if they can compose a five-pointed star. Otherwise, print No. (If 5 points are the same, print Yes. )
 

Sample Input
2 3.0000000 0.0000000 0.9270509 2.8531695 0.9270509 -2.8531695 -2.4270509 1.7633557 -2.4270509 -1.7633557 3.0000000 1.0000000 0.9270509 2.8531695 0.9270509 -2.8531695 -2.4270509 1.7633557 -2.4270509 -1.7633557
 

Sample Output
Yes No
Hint
 

题意:给出5个点,判断能不能组成正5角星。

这题还是贴官方给的题解吧:

容易看出只需要判断这5个点是否在一个正五边形上。

因此我们枚举排列,然后依次判断即可。

判定方法是,五条相邻边相等,五条对角线相等。

当然题目给的精度问题,窝只能说,如果泥做法不复杂,精度足够好的话,是可以过的。毕竟题目说的小于10−410^{-4}104是指理论上的,所以理论上适用所有的数之间的比较。所以有人问我开方前和开方后,我只能说,哪个精度高用哪个....

当然你也可以先求出凸包然后再判相邻距离......


数据比较弱,我枚举每个点的最长边,再判断每个最长边是否相等,居然过了,代码如下:


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
double x[6],y[6],len[6];
double max[6]; 
int main()
{
    int i,t,j,k;
    scanf("%d",&t);
    while(t--)
    {
        for(i=0;i<5;++i)
        {
            scanf("%lf%lf",&x[i],&y[i]);
            max[i]=0;
        }
        for(i=0;i<5;++i)
        {
            for(j=0;j<5;++j)
            {
                if(i!=j)
                {
                    len[i]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
                    if(max[i]<len[i])
                        max[i]=len[i]; 
                }
            }
        }
        int sign=0;
        for(i=0;i<5;++i)
        {
            for(j=0;j<5;++j)
            {
                if(i!=j&&fabs(max[i]-max[j])>1e-4)
                {
                    sign=1;
                    break;
                }
                if(max[i]==0||max[j]==0)
                {
                    sign=1;
                    break;
                }
            }
            if(sign)
                break;
        }
        if(sign)
            printf("No\n");
        else
            printf("Yes\n"); 
    }
    return 0;
} 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值