题目意思:
很简单的题目意思,给你一系列的点的坐标,问你可以用这些点构造多少正多边形
其实就是找正方形的个数 这个是一个结论
等我晚上吃完饭回来 让总结
先上代码:
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1000+5;
int N,ans;
struct SPoint {
double x,y;
SPoint() {}
SPoint(int xx,int yy) : x(xx), y(yy) {}
bool operator < (const SPoint& p) const {
if(x == p.x) return y < p.y;
return x < p.x;
}
bool operator == (const SPoint& p) const {
return x==p.x&&y==p.y;
}
}pnt[maxn];
//任意点(x,y),绕一个坐标点(rx0,ry0)逆时针旋转a角度后的新的坐标设为(x0, y0),有公式:
//x0= (x - rx0)*cos(a) - (y - ry0)*sin(a) + rx0 ;
//y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ;
void transXY(SPoint A, SPoint B, SPoint &C, int f) {
int tx = B.x - A.x, ty = B.y - A.y;
C.x = A.x - ty * f;
C.y = A.y + tx * f;
}
int main() {
//freopen("input.in","r",stdin);
while(~scanf("%d",&N)&&N)
{
ans = 0;
for(int i = 0;i < N;i++) scanf("%lf %lf",&pnt[i].x,&pnt[i].y);
sort(pnt,pnt+N);
for(int i = 0;i < N-3;i++) //①
{
for(int j = i+1;j < N-2;j++) //②
{
SPoint C,D;
transXY(pnt[i],pnt[j],C,1);
transXY(pnt[j],pnt[i],D,-1);
if(binary_search(pnt+j,pnt+N,C)&&binary_search(pnt+j,pnt+N,D)) ans++; //③
transXY(pnt[i],pnt[j],C,-1);
transXY(pnt[j],pnt[i],D,1);
if(binary_search(pnt+j,pnt+N,C)&&binary_search(pnt+j,pnt+N,D)) ans++; //④
}
}
printf("%d\n",ans);
}
return 0;
}