hdu5365 簡單幾何問題

life4711發表於2015-08-09

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

Problem Description
AFA is a girl who like runing.Today,he download an app about runing .The app can record the trace of her runing.AFA will start runing in the park.There are many chairs in the park,and AFA will start his runing in a chair and end in this chair.Between two chairs,she running in a line.she want the the trace can be a regular triangle or a square or a regular pentagon or a regular hexagon.
Please tell her how many ways can her find.
Two ways are same if the set of chair that they contains are same.
 

Input
There are multiply case.
In each case,there is a integer n(1 < = n < = 20)in a line.
In next n lines,there are two integers xi,yi(0 < = xi,yi < 9) in each line.
 

Output
Output the number of ways.
 

Sample Input
4 0 0 0 1 1 0 1 1
 

Sample Output
1

/**
hdu5365  簡單幾何問題
題目大意:小花是一個熱愛健身的姑娘,這天她下載了一個跑步軟體,這個軟體可以記錄下小花跑步的軌跡。小花決定去公園跑步。
          公園裡有許許多多的座椅,小花希望在一些座椅休息一下,並且她在兩條座椅之間只跑直線。小花是一個完美主義者,
          她希望自己最後的軌跡是一個正三邊形或者正四邊形或者正五邊形或者正六邊形。小花會從某條座椅開始開啟跑步軟體,
          並在回到這個座椅後關閉。請問小花有多少種跑法。注:若兩種跑法經過的座椅集合相同則認為是一種跑法。且經過一
          條座椅時沒有必要一定停下來
解題思路:地球人都知道整點是不能構成正五邊形和正三邊形和正六邊形的,所以只需暴力列舉四個點判斷是否是正四邊形即可。
          假如你不是地球人,那麼即使暴力列舉正三邊形和稍微不那麼暴力地找正五邊形和正六邊形也是可以通過的(反正找不到)。
*/
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

struct note
{
    int x,y;
}a[105];
int n;

int len(int x,int y,int u,int v)
{
    return (x-u)*(x-u)+(y-v)*(y-v);
}

int judge(int i,int j,int k,int l)///片面內給定四個點的座標判斷是否構成正方形(求出各邊長,排序,判斷邊的關係)
{
    vector <int> vec;
    vec.push_back(len(a[i].x,a[i].y,a[j].x,a[j].y));
    vec.push_back(len(a[i].x,a[i].y,a[k].x,a[k].y));
    vec.push_back(len(a[i].x,a[i].y,a[l].x,a[l].y));
    vec.push_back(len(a[j].x,a[j].y,a[k].x,a[k].y));
    vec.push_back(len(a[k].x,a[k].y,a[l].x,a[l].y));
    vec.push_back(len(a[l].x,a[l].y,a[j].x,a[j].y));
    sort(vec.begin(),vec.end());
    if(vec[0]==vec[1]&&vec[1]==vec[2]&&vec[2]==vec[3]&&vec[1]*2==vec[4]&&vec[4]==vec[5])
        return true;
    return false;
}
int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&a[i].x,&a[i].y);
        }
        int sum=0;
        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++)
                    {
                        if(judge(i,j,k,l))sum++;
                    }
                }
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}


相關文章