HDU 5365 Run 计算几何 枚举 组合

Run

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


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
 

因为题目说所有的坐标都是整数,因此我们直接就可以判断出不可能出现正三角形,正五边形和正六边形,因此,只可能出现正方形,于是,我们需要做的就是枚举出所有四个点的组合,然后判断出这四个点能否构成正方形就可以了,判断的方法为取一组临边向量,CA,CD,以及对边向量,CB,首先,|CA|=|CD|,且CA与CD垂直,且CB=CA+CD。枚举可以使用四重循环或者递归。

#include <iostream>
#include <algorithm>
#include <memory.h>
using namespace std;

struct Point
{
    int x;
    int y;
};
long long ans;
Point point[30];
int select[4];
int visit[30];
int n;

int cmp(const Point &a,const Point &b)
{
    if(a.x<b.x)
        return 1;
    else if(a.x==b.x&&a.y<b.y)
        return 1;
    else
        return 0;
}

int check()
{
    int flag=1;
    Point temp[4];
    for(int i=0;i<4;i++)
    {
    	temp[i]=point[select[i]];
	}
    sort(temp,temp+4,cmp);
    Point a[3];
    /*
    for(int i=0;i<4;i++)
    {
    	cout<<point[i].x<<point[i].y<<endl;
	}
	getchar();
	return 1;*/
    
    for(int i=0;i<3;i++)
    {
        a[i].x=temp[i+1].x-temp[0].x;
        a[i].y=temp[i+1].y-temp[0].y;
    }
    if((a[0].x*a[0].x+a[0].y*a[0].y)!=(a[1].x*a[1].x+a[1].y*a[1].y))//两向量大小相等
        flag=0;
    if(flag)
    {
        if((a[0].x*a[1].x+a[0].y*a[1].y)!=0)//两向量垂直
            flag=0;
    }
    if(flag)
    {
        if(((a[0].x+a[1].x)!=(a[2].x))||((a[0].y+a[1].y)!=(a[2].y)))//四点共面
            flag=0;
    }
    
    return flag;

}

void show()
{
    for(int i=0;i<4;i++)
    {
        cout<<select[i]<<' ';
    }
    cout<<endl;
}

void Find(int Count,int next)//组合 
{
    if(Count==4)
    {
        //show();
        if(check())
            ans++;
        return;
    }
    for(int i=next;i<n;i++)
    {
        if(!visit[i])
        {
            select[Count]=i;
            visit[i]=1;
            Find(Count+1,i+1);
            visit[i]=0;
        }

    }
}

int main()
{

    int i;
    while(cin>>n)
    {
        ans=0;
        memset(visit,0,sizeof(visit));
        for(i=0;i<n;i++)
            cin>>point[i].x>>point[i].y;
        Find(0,0);
        cout<<ans<<endl;
    }


    return 0;
}








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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值