hdu5563 ( Clarke and five-pointed star )

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
//point
const double eps = 1e-8;
const double PI = acos(-1.0);
int sgn(double x) {
    if(fabs(x)<eps) return 0;
    if(x < 0) return -1;
    else return 1;
}
struct Point{
    double x, y;
    Point() {}
    Point(double _x, double _y){
        x = _x; y = _y;
    }
    Point operator -(const Point& b)const {
        return Point(x - b.x, y-b.y);
    }
    double operator ^(const Point& b)const {
        return x*b.y-y*b.x;
    }
    double operator *(const Point& b)const {
        return x*b.x+y*b.y;
    }
    int operator ==(const Point& b)const{  //精度处理   判断两点是否相等 
        return !(sgn(x-b.x)&&sgn(y-b.y));
    }

    void transXY(double B){
        double tx = x, ty = y;
        x = tx*cos(B)-ty*sin(B);
        y = tx*sin(B)+ty*cos(B);
    }
};
double dist(Point a, Point b){
    return sqrt((a-b)*(a-b));
}

bool jg(Point* P,int n){
    int a[5] = {0, 1, 2, 3, 4};
    do{
        int ok = 1; 
        double bz1 = dist(P[a[0]], P[a[2]]); 
        for(int i = 1; i < 5; i++){
            if(fabs(bz1-dist(P[a[i]], P[a[(i+2)%5]]))>=1e-4)//比较他们的对角线长度
            {    
                    ok = 0;
                    break;
            }
        }
        double bz2 = dist(P[a[0]], P[a[1]]);
        for(int i = 1; i < 5; i++){
            if(fabs(bz2-dist(P[a[i]], P[a[(i+1)%5]]))>=1e-4)//比较相邻边的长度 
            {    
                    ok = 0;
                    break;
            }
        }
        if(ok) return 1; 
    }while(next_permutation(a, a+n));
    return 0;
}


int main() {
    Point a[5];
    int n; 
    scanf("%d", &n);
    while(n--){
        for(int i = 0; i < 5; i++) {
            cin >> a[i].x >> a[i].y ;
        }
        if(jg(a, 5))cout << "Yes" << endl;
        else cout << "No"<< endl;
    } 
    
} 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值