关闭

BestCoder Round #62 (div.2) HDOJ5563 Clarke and five-pointed star(计算几何)

670人阅读 评论(0) 收藏 举报
分类:

Clarke and five-pointed star

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


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 integer T(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 than 104
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


题目链接:点击打开链接

判断5条边是否相等以及5条对角线是否相等, 由于题目中给出的点的坐标未必相邻,  那么枚举每一个点与其他四个点求出距离, 排序后

如果前十个点以及后十个点分别在误差范围内, 那么就可以组成五角星.

AC代码:

#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
using namespace std;
typedef long long ll;
const int MAXN = 10;
struct node
{
    /* data */
    double x, y;
}a[MAXN];
double len[MAXN * MAXN];
double dis(node a, node b)
{
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
bool judge(double a, double b)
{
    if(fabs(a - b) <= 1e-4) return true;
    return false;
}
int main(int argc, char const *argv[])
{
    int t;
    scanf("%d", &t);
    while(t--) {
        memset(len, -1, sizeof(len));
        bool flag = false;
        for(int i = 0; i < 5; ++i)
            scanf("%lf%lf", &a[i].x, &a[i].y);
        int num = 0;
        for(int i = 0; i < 5; ++i)
            for(int j = 0; j < 5; ++j)
                if(i == j) continue;
                else len[num++] = dis(a[i], a[j]); 
        sort(len, len + num);
        for(int i = 0; i < 9; ++i)
            if(!judge(len[i], len[i + 1])) {
                flag = true;
                break;
            }
        for(int i = 10; i < 19; ++i)
            if(!judge(len[i], len[i + 1])) {
                flag = true;
                break;
            }
        if(flag) printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:250789次
    • 积分:7335
    • 等级:
    • 排名:第2979名
    • 原创:291篇
    • 转载:7篇
    • 译文:0篇
    • 评论:14条
    联系方式

    QQ: 200756783

    WeChat: 7632592

    Mail: gkhack@qq.com

    WeiBo: GameKingHack

    博客专栏