HDU 5365 Run (简单分析+暴力枚举)

Run

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


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
 

Source
 

问题描述
小花是一个热爱健身的姑娘,这天她下载了一个跑步软件,这个软件可以记录下小花跑步的轨迹。小花决定去公园跑步。公园里有许许多多的座椅,小花希望在一些座椅休息一下,并且她在两条座椅之间只跑直线。小花是一个完美主义者,她希望自己最后的轨迹是一个正三边形或者正四边形或者正五边形或者正六边形。小花会从某条座椅开始打开跑步软件,并在回到这个座椅后关闭。
请问小花有多少种跑法。注:若两种跑法经过的座椅集合相同则认为是一种跑法。且经过一条座椅时没有必要一定停下来
输入描述
输入有多组数据
每组数据第一行为一个n(1 < = n < = 20)表示座椅数量
接下来n行,每行两个整数xi,yi(0 < = xi,yi < = 8)表示座椅的坐标
输出描述
输出方案数
输入样例
4
0 0
0 1
1 0
1 1
输出样例
1

解题思路:对于整数点,任意的三个点是无法构成正等三角形的,同样对于任意的整数点也无法构成正无边形和正六边形。因此只有可能是正四边形,而题目的数据不大,直接暴力枚举。


代码如下:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
#include <limits.h>
#define debug "output for debug\n"
#define pi (acos(-1.0))
#define eps (1e-6)
#define inf (1<<28)
#define sqr(x) (x) * (x)
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;

struct point
{
    int x,y;
}a[25];

int dis(point a,point b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
//四条边相等,两条对角线相等
int solve(point a,point b,point c,point d)
{
    int di[10];
    di[0]=dis(a,b);
    di[1]=dis(c,d);
    di[2]=dis(a,c);
    di[3]=dis(b,d);
    di[4]=dis(a,d);
    di[5]=dis(b,c);
    sort(di,di+6);
    if(di[5]==di[4]&&di[0]==di[1]&&di[2]==di[3]&&di[0]==di[2])
        return 1;
    return 0;
}

int main()
{
    int i,j,k,l,n,ans;
    while(~scanf("%d",&n))
    {
        for(i=0;i<n;i++)
            scanf("%d%d",&a[i].x,&a[i].y);
        if(n<4)
        {
            printf("0\n");
            continue;
        }
        ans=0;
        for(i=0;i<n;i++)
        {
            for(j=i+1;j<n;j++)
            {
                for(k=j+1;k<n;k++)
                {
                    for(l=k+1;l<n;l++)
                    {
                        if(solve(a[i],a[j],a[k],a[l]))
                            ans++;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值