题意:给了很多整数点,找能组成的正多边形的个数。
思路:在整数点上的正多边形,就只有正方形了。把每个点都存下来,遍历每两个点,看看与它们组成正方形的另外两个存不存在。最后ans/4。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<vector>
#include<list>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<numeric>
#include<functional>
using namespace std;
const int maxn = 2e3+5;
map<long long,int> ma;
long long a[maxn],b[maxn];
long long x,y,ans;
long long ha(long long x,long long y)
{
return (x+10000)*100000+y;
}
int main(void)
{
int n,i,j,k;
while(scanf("%d",&n)!=EOF)
{
ma.clear();
for(i = 1; i <= n; i++)
{
scanf("%lld%lld",&x,&y);
a[i] = x;
b[i] = y;
ma[ha(x,y)] = 1;
}
ans = 0;
for(i = 1; i <= n; i++)
{
for(j = i+1; j <= n; j++)
{
long long x1,x2,y1,y2,x3,x4,y3,y4;
x1 = a[i];y1 = b[i];
x2 = a[j];y2 = b[j];
x3 = x1+y2-y1;
y3 = y1-x2+x1;
x4 = x2+y2-y1;
y4 = y2-x2+x1;
if(ma.find(ha(x3,y3))!=ma.end() && ma.find(ha(x4,y4))!=ma.end())
ans++;
x3 = x1-y2+y1;
y3 = y1+x2-x1;
x4 = x2-y2+y1;
y4 = y2+x2-x1;
if(ma.find(ha(x3,y3))!=ma.end() && ma.find(ha(x4,y4))!=ma.end())
ans++;
}
}
ans /= 4;
printf("%lld\n",ans);
}
return 0;
}