题目背景:
AtCoder Beginner Contest 218(taskD):
问题描述:
We have N distinct points on a two-dimensional plane, numbered 1,2,…,N. Point i (1≤i≤N) has the coordinates (xi,yi).How many rectangles are there whose vertices are among the given points and whose edges are parallel to the x- or y-axis?
在二维平面上给n个坐标,求坐标能构成的所有平行于X,Y轴的矩形的数目.
样例:
input
6
0 0
0 1
1 0
1 1
2 0
2 1
output
3
input
4
0 1
1 2
2 3
3 4
output
0
代码实现:
#include<iostream>
using namespace std;
int main()
{
int a,n,i,j,l,k;
cin>>n; //输入点的个数
int b[n],c[n];
for(i=0;i<n;i++) //将各点输入
cin>>b[i]>>c[i];
for(i=0;i<n;i++) //从第一个点开始循环
{
for(j=i+1;j<n;j++)
{
if(b[i]==b[j]) //如果存在与该点横坐标相等的点
{
for(k=i+1;k<n;k++)
{
if(c[i]==c[k])//如果存在与该点纵坐标相等的点
{
for(l=i+1;l<n;l++)
{
if(b[k]==b[l] && c[j]==c[l]) //遍历是否存在与刚才两个点的纵横坐标相匹配的横纵坐标
a=a+1;//若存在则计数加一
}
}
}
}
}
}
cout<<a;
return 0;
}