HDU 5365 Run

题意:给n个整点,问用其中若干个做顶点能够成多少个正三角形或正四边形或正五边形或正六边形。

 

解法:出题人说

地球人都知道整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可。假如你不是地球人,那么即使暴力枚举正三边形和稍微不那么暴力地找正五边形和正六边形也是可以通过的(反正找不到)。

然而我的数学是体育老师教的……判正方形也写不明白……【哭晕在厕所

 

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long

using namespace std;

struct node
{
    int x, y;
    node(int x, int y) : x(x), y(y) {}
    node() {}
} point[25];
bool judge2(node a, node b, node c)
{
    if(((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) == (c.x - b.x) * (c.x - b.x) + (c.y - b.y) * (c.y - b.y)) &&
            ((a.x - b.x) * (c.x - b.x) + (a.y - b.y) * (c.y - b.y) == 0))
        return true;
    else return false;
}
int judge1(node a, node b, node c)
{
    if(judge2(a, b, c))
        return 1;
    if(judge2(b, a, c))
        return 2;
    if(judge2(a, c, b))
        return 3;
    return 0;
}
int main()
{
    int n;
    while(~scanf("%d", &n))
    {
        int ans = 0;
        for(int i = 0; i < n; i++)
        {
            int a, b;
            scanf("%d%d", &a, &b);
            point[i] = node(a, b);
        }
        for(int i = 0; i < n; i++)
            for(int j = i + 1; j < n; j++)
                for(int k = j + 1; k < n; k++)
                    for(int l = k + 1; l < n; l++)
                    {
                        int tmp = judge1(point[i], point[j], point[k]);
                        if(tmp)
                        {
                            if(tmp == 1)
                            {
                                if(judge2(point[i], point[l], point[k])) ans++;
                            }
                            else if(tmp == 2)
                            {
                                if(judge2(point[j], point[l], point[k])) ans++;
                            }
                            else
                            {
                                if(judge2(point[i], point[l], point[j])) ans++;
                            }
                        }
                    }
        printf("%d\n", ans);
    }
    return 0;
}

  

posted @ 2015-08-11 10:20  露儿大人  阅读(125)  评论(0编辑  收藏  举报