HDU6055 2017 Multi-University Training Contest - Team 2 K - Regular polygon(暴力枚举)

Regular polygon

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1459    Accepted Submission(s): 567


Problem Description
On a two-dimensional plane, give you n integer points. Your task is to figure out how many different regular polygon these points can make.
 

Input
The input file consists of several test cases. Each case the first line is a numbers N (N <= 500). The next N lines ,each line contain two number Xi and Yi(-100 <= xi,yi <= 100), means the points’ position.(the data assures no two points share the same position.)
 

Output
For each case, output a number means how many different regular polygon these points can make.
 

Sample Input
  
  
4 0 0 0 1 1 0 1 1 6 0 0 0 1 1 0 1 1 2 0 2 1
 

Sample Output
  
  
1 2
 

Source
 

Recommend
liuyiding
 

题目思路:给N个点的坐标,要求输出能够组成正多边形的个数
解题思路:经过研究发现,只能存在正方形一种情况,所以只考虑正方形即可,n的立方的复杂度会T,我们只能枚举两个点,然后通过两个点去判是否能够组成一个正方形,同时在枚举两个点的时候,要判重,判重的方式就是在枚举第一个点后,第二个点的判断条件是在第一个点的第一象限位置内进行枚举
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

int tu[505][505];
int sum,n;
struct point
{
	int x,y;
}p[505];
bool cmp(point x,point y)
{
	if(x.x==y.x)
		return x.y<y.y;
	return x.x<y.x;
}
int main()
{
 //freopen("in.txt","r",stdin);
 //freopen("out.txt","w",stdout);
	while(cin>>n)
	{
		int i,j;
		int xx,yy;
		int bx,by,cy,cx;
		memset(p,0,sizeof(p));
		memset(tu,0,sizeof(tu));
		sum=0;
		for(i=1;i<=n;i++)
		{
			cin>>p[i].x>>p[i].y;
			p[i].x+=100;
			p[i].y+=100;
			tu[p[i].x][p[i].y]=1;
		}
		sort(p+1,p+1+n,cmp);
		for(i=1;i<=n;i++)
		{
			for(j=i+1;j<=n;j++)
			{
				bool flag=0;
				if(p[j].x>p[i].x&&p[j].y>=p[i].y)
				{
					xx=p[j].x-p[i].x;
					yy=p[j].y-p[i].y;
					bx=p[j].x-yy,cx=p[i].x-yy;
					by=p[j].y+xx;cy=p[i].y+xx;
					//cout<<p[i].x<<" "<<p[i].y<<" "<<p[j].x<<" "<<p[j].y<<endl;
					//cout<<bx<<" "<<by<<" "<<cx<<" "<<cy<<endl;
					//cout<<"--------------------"<<endl;
					if(bx>=0&&bx<=200&&by>=0&&by<=200&&cx<=200&&cx>=0&&cy<=200&&cy>=0)
					{
						if(tu[bx][by]==1&&tu[cx][cy]==1)
							flag=1;
					}

				}
				if(flag==1)
					sum++;
			}
		}
		cout<<sum<<endl;
	}
 
 return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值