HDU6055 2017 Multi-University Training Contest

来源:互联网 发布:微信发淘宝优惠券坏处 编辑:程序博客网 时间:2024/05/21 10:04

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
40 00 11 01 160 00 11 01 12 02 1
 

Sample Output
12
 

Source
2017 Multi-University Training Contest - Team 2
 

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;}