• hdu 5563 Clarke and five-pointed star 水题


    Clarke and five-pointed star

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=5563

    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 integer T(1≤T≤10), the number of the test cases.
    For each test case, 5 lines follow. Each line contains 2 real numbers xi,yi(−109≤xi,yi≤109), denoting the coordinate of this point.

    Output

    Two numbers are equal if and only if the difference between them is less than 10−4.
    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

    题意

    给你五个点,问你是否能够构成一个正五边形,精度要求1e-4

    题解:

    直接判断是否有五条边相同,是否有五条对角线长度相同就好了

    代码

    #include<iostream>
    #include<stdio.h>
    #include<map>
    #include<vector>
    #include<algorithm>
    #include<math.h>
    using namespace std;
    const double eps = 1e-6;
    struct node
    {
        double x,y;
    };
    node p[12];
    vector<double> Q;
    double dis(node a,node b)
    {
        return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    }
    int is_equal(double x,double y)
    {
        return fabs(x-y)<eps;
    }
    map<long long,int> H;
    int main()
    {
        int t;scanf("%d",&t);
        for(int cas=1;cas<=t;cas++)
        {
            H.clear();
            Q.clear();
            for(int i=0;i<5;i++)
                scanf("%lf%lf",&p[i].x,&p[i].y);
            for(int i=0;i<5;i++)
            {
                for(int j=i+1;j<5;j++)
                {
                    Q.push_back(dis(p[i],p[j]));
                }
            }
            int flag = 0;
            sort(Q.begin(),Q.end());
            for(int i=0;i<Q.size();i++)
            {
                long long p = (100000.0*Q[i])*1LL;
                if(H[p]==0)
                {
                    H[p]++;
                    flag++;
                }
                else
                    H[p]++;
            }
            if(flag>2)
            {
                printf("No
    ");
                continue;
            }
            long long p1 = 1LL*(100000.0*Q[0]);
            long long p2 = 1LL*(100000.0*Q[9]);
            if(H[p1]==10)
            {
                printf("Yes
    ");
                continue;
            }
            if(H[p1]!=5&&H[p2]!=5)
            {
                printf("No
    ");
                continue;
            }
            printf("Yes
    ");
        }
    }
  • 相关阅读:
    JS小技巧总汇
    [转贴]聪明人如何拯救你的职业困
    Button按钮多行显示的实现方法
    事件和委托
    支持~
    关于递归
    Android 资源的国际化
    Android 文件的浏览(类似于FileDialog的功能)
    Android 开发TCP、UdP客户端
    Android 为什么现在google不让结束整个程序,只让结束单个Activity(转)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4965834.html
Copyright © 2020-2023  润新知