1004 画画
题 意:durong拿起了apple pencil,开始在他的ipad上面学习画画。他随便画了很多个点,这时候他突然在想,这些点可以构成多少个矩形呢?
输入描述:
第一行一个整数n代表点的个数。
接下来n行每行两个整数x,y代表点的坐标。
n <= 1000
|x|, |y| <= 30000
输出描述
输出一个整数,代表矩形的个数。
输入样例:
6
0 1
1 0
1 1
0 0
-1 0
0 -1
输出样例:
2
思 路:一个矩阵,可以由对称轴的长度和中心点唯一确定。然后n^2去枚举一下就好了
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<ll,P> LP;
const int maxn = 3e4+5;
map<LP,int> mp;
int n;
int x[maxn],y[maxn];
int main(){
scanf("%d",&n);
ll ans = 0 ;
for(int i=0;i<n;i++){
scanf("%d %d",&x[i],&y[i]);
}
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(j == i) continue;
int x1 = x[i]+x[j];
int y1 = y[i]+y[j];
ll len = (y[i]-y[j])*(y[i]-y[j]) + (x[i]-x[j])*(x[i]-x[j]);
LP lp;lp.first = len;
P p;p.first=x1;p.second=y1;
lp.second=p;
if(mp[lp])ans++;
else mp[lp]++;
}
}
printf("%lld\n",ans);
return 0;
}