hdu5563 ( Clarke and five-pointed star )

来源:互联网 发布:俄罗斯生活知乎 编辑:程序博客网 时间:2024/05/16 13:42
#include<iostream>#include<algorithm>#include<cstdio>#include<cmath>using namespace std;//pointconst 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;    }     } 

0 0
原创粉丝点击