标签:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
int x[30],y[30];
class Coordinate
{
public:
double xCoordinate;
double yCoordinate;
Coordinate(double x = 0,double y = 0)
{
this->xCoordinate = x;
this->yCoordinate = y;
}
bool operator!=(Coordinate const &comp) const
{
return (this->xCoordinate != comp.xCoordinate ||
this->yCoordinate != comp.yCoordinate);
}
}tp[10];
bool Judge(Coordinate const x,Coordinate const y,Coordinate const z)
{
Coordinate *mVector = new Coordinate(x.xCoordinate - y.xCoordinate,
x.yCoordinate - y.yCoordinate);
Coordinate *nVector = new Coordinate(z.xCoordinate -
(x.xCoordinate + y.xCoordinate)/2,
z.yCoordinate -
(x.yCoordinate + y.yCoordinate)/2);
bool result = ((mVector->xCoordinate * nVector->xCoordinate +
mVector->yCoordinate * nVector->yCoordinate) == 0);
if(result)
result = (mVector->xCoordinate * mVector->xCoordinate +
mVector->yCoordinate * mVector->yCoordinate)
== ((nVector->xCoordinate * nVector->xCoordinate +
nVector->yCoordinate * nVector->yCoordinate) * 4);
delete mVector;
delete nVector;
return result;
}
bool IsSquare(Coordinate *tp,int length)
{
if(length != 4)
return false;
int a,b,c;
if(Judge(tp[0],tp[1],tp[2]))
{
a = 0;
b = 1;
c = 2;
}
else if(Judge(tp[0],tp[2],tp[1]))
{
a = 0;
b = 2;
c = 1;
}
else if(Judge(tp[2],tp[1],tp[0]))
{
a = 1;
b = 2;
c = 0;
}
else
return false;
return (tp[3] != tp[c] && Judge(tp[a],tp[b],tp[3]));
}
int main()
{
while(~scanf("%d",&n)){
int ans=0;
for(int i=0;i<n;i++)
scanf("%d%d",&x[i],&y[i]);
for(int a=0;a<n;a++)
for(int b=a+1;b<n;b++)
for(int c=b+1;c<n;c++)
for(int d=c+1;d<n;d++)
{
tp[0].xCoordinate=x[a];tp[0].yCoordinate=y[a];
tp[1].xCoordinate=x[b];tp[1].yCoordinate=y[b];
tp[2].xCoordinate=x[c];tp[2].yCoordinate=y[c];
tp[3].xCoordinate=x[d];tp[3].yCoordinate=y[d];
if(IsSquare(tp,4)) ans++;
}
printf("%d\n",ans);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/xinag578/article/details/47374051