HDU 5365 Run

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
 


格点上其实是不存在正三角形,正五边形,正六边形的,反正暴力上就好了

#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = 200005;
int T, n, m, x[maxn], y[maxn], a[maxn], ans, c[maxn];

bool check(int u)
{
    int tot = 0;
    for (int i = 1; i < u;i++)
        for (int j = i + 1; j <= u; j++)
            c[tot++] = (x[a[i]] - x[a[j]])*(x[a[i]] - x[a[j]]) + (y[a[i]] - y[a[j]])*(y[a[i]] - y[a[j]]);
    sort(c, c + tot);
    if (u == 3 && c[0] == c[2]) return true;
    if (u == 4 && c[0] == c[3] && c[4] == c[5] && c[4] == c[0] + c[3]) return true;
    if (u == 6 && c[0] == c[5] && c[6] == c[11] && c[6] == 3 * c[0] && c[12] == c[14] && c[12] == 4 * c[0]) return true;
    return false;
}

void dfs(int x, int y, int z)
{
    if (x > z)
    {
        if (check(z)) ans++;
        return;
    }
    for (int i = y; i <= n; i++)
    {
        a[x] = i;
        dfs(x + 1, i + 1, z);
    }
}

int main()
{
    //scanf("%d", &T);
    while (scanf("%d", &n) != EOF)
    {
        ans = 0;
        for (int i = 1; i <= n; i++)
        {
            scanf("%d%d", &x[i], &y[i]);
        }
        for (int i = 3; i <= 6; i++)
        {
            if (i != 5) dfs(1, 1, i);
        }
        printf("%d\n", ans);
    }
    return 0;
}


你可能感兴趣的:(HDU)