hdu5533 Dancing Stars on Me

原题:hdu5533

题意:给你一组点对,问是否能组成一个正多边形

分析:正多边形任意的重心到每个点的距离是相等,每次枚举三个点构成求重心判断所有的重心是否相等

重心:

x=(2*(y3-y2)*(x2*x2+y2*y2-x1*x1-y1*y1)-2*(y2-y1)*(x3*x3+y3*y3-x2*x2-y2*y2))/(4*(y3-y2)*(x2-x1)-4*(y2-y1)*(x3-x2));

y=((-2)*(x3-x2)*(x2*x2+y2*y2-x1*x1-y1*y1)+2*(x2-x1)*(x3*x3+y3*y3-x2*x2-y2*y2))/(4*(y3-y2)*(x2-x1)-4*(y2-y1)*(x3-x2));

#include<cstdio>
#include<iostream>
using namespace std;
struct po
{
    double x,y;
}cl[105];
double d(po p1,po p2)
{
    return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
}
po ca(po p1,po p2,po p3)
{
    po p;
    double x1 = p1.x,y1 = p1.y;
    double x2 = p2.x,y2 = p2.y;
    double x3 = p3.x,y3 = p3.y;
    p.x = (2*(y3-y2)*(x2*x2+y2*y2-x1*x1-y1*y1)-2*(y2-y1)*(x3*x3+y3*y3-x2*x2-y2*y2))/(4*(y3-y2)*(x2-x1)-4*(y2-y1)*(x3-x2));
    p.y = ((-2)*(x3-x2)*(x2*x2+y2*y2-x1*x1-y1*y1)+2*(x2-x1)*(x3*x3+y3*y3-x2*x2-y2*y2))/(4*(y3-y2)*(x2-x1)-4*(y2-y1)*(x3-x2));
    return p;
}
bool pd(po p1,po p2,po p3)
{
    double x1 = p1.x,y1 = p1.y;
    double x2 = p2.x,y2 = p2.y;
    double x3 = p3.x,y3 = p3.y;
    if((y1-y2)*(x1-x3) == (x1-x2)*(y1-y3))
        return 0;
    else
        return 1;
}
int main()
{
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i = 0; i < n; i++)
            cin>>cl[i].x>>cl[i].y;
        if(n == 3)
        {
            if(d(cl[0],cl[1]) == d(cl[1],cl[2]) && d(cl[0],cl[1]) == d(cl[0],cl[2]))
                cout<<"YES"<<endl;
            else
                cout<<"NO"<<endl;
        }
        else
        {
            if(pd(cl[0],cl[1],cl[2]))
            {
                double x = ca(cl[0],cl[1],cl[2]).x;
                double y = ca(cl[0],cl[1],cl[2]).y;
                //cout<<x<<endl;
                //cout<<y<<endl;
                int flag = 1;
                for(int i = 0; i < n-2; i++)
                {
                    for(int j = i+1; j < n-1; j++)
                    {
                        for(int k = j+1; k < n; k++)
                        {
                            if(!pd(cl[i],cl[j],cl[k]))
                            {
                                cout<<"NO"<<endl;
                                flag = 0;
                                break;
                            }
                            else
                            {
                                if(ca(cl[i],cl[j],cl[k]).x != x || ca(cl[i],cl[j],cl[k]).y != y)
                                {
                                    cout<<"NO"<<endl;
                                    flag = 0;
                                    break;
                                }
                            }
                        }
                        if(!flag)
                            break;
                    }
                    if(!flag)
                        break;
                }
                if(flag)
                    cout<<"YES"<<endl;
            }
            else
                cout<<"NO"<<endl;
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值