codeforce 660D Number of Parallelograms
题意:询问多少个矩形。
统计横纵坐标差,放进vector中
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<queue> 5 #include<stack> 6 #include<bits/stdc++.h> 7 using namespace std; 8 #define LL long long 9 int x[2010],y[2010]; 10 vector<pair<int,int> >v; 11 int main(){ 12 int n; 13 while(~scanf("%d",&n)){ 14 for(int i=0;i<n;i++) 15 scanf("%d%d",&x[i],&y[i]); 16 17 for(int i=0;i<n;i++){ 18 for(int j=i+1;j<n;j++){ 19 //cout<<"~~"<<endl; 20 int dx=x[i]-x[j]; 21 int dy=y[i]-y[j]; 22 if(dx<0||(dx==0&&dy<0)){ 23 dx=-dx,dy=-dy; 24 } 25 v.push_back(make_pair(dx,dy)); 26 } 27 } 28 //cout<<"~~"<<endl; 29 sort(v.begin(),v.end()); 30 //printf("size:%d\n",v.size()); 31 LL cnt=0; 32 LL ans=0; 33 for(int i=0;i<(int)v.size()-1;i++){ 34 cnt++; 35 if(v[i+1]!=v[i]){ 36 ans+=cnt*(cnt-1)/2; 37 cnt=0; 38 } 39 } 40 printf("%I64d\n", ans/2); 41 } 42 return 0; 43 }