codeforces_660D. Number of Parallelograms
2016-04-16 23:58
316 查看
D. Number of Parallelograms
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.
Input
The first line of the input contains integer n (1 ≤ n ≤ 2000) — the number of points.
Each of the next n lines contains two integers (xi, yi) (0 ≤ xi, yi ≤ 109) — the coordinates of the i-th point.
Output
Print the only integer c — the number of parallelograms with the vertices at the given points.
Example
input
4
0 1
1 0
1 1
2 0
output
1
判断有几个平行四边形,可以找出所有对角线中点,每一对中点相等确定一个平行四边形。
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.
Input
The first line of the input contains integer n (1 ≤ n ≤ 2000) — the number of points.
Each of the next n lines contains two integers (xi, yi) (0 ≤ xi, yi ≤ 109) — the coordinates of the i-th point.
Output
Print the only integer c — the number of parallelograms with the vertices at the given points.
Example
input
4
0 1
1 0
1 1
2 0
output
1
判断有几个平行四边形,可以找出所有对角线中点,每一对中点相等确定一个平行四边形。
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <stack> #include <bitset> #include <queue> #include <set> #include <map> #include <string> #include <algorithm> #define Si(a) scanf("%d",&a) #define Sl(a) scanf("%lld",&a) #define Sd(a) scanf("%lf",&a) #define Ss(a) scanf("%s",a) #define Pi(a) printf("%d\n",(a)) #define Pl(a) printf("%lld\n",(a)) #define Pd(a) printf("%lf\n",(a)) #define Ps(a) printf("%s\n",(a)) #define W(a) while(a--) #define mem(a,b) memset(a,(b),sizeof(a)) #define FOP freopen("data.txt","r",stdin) #define inf 0x3f3f3f3f #define maxn 1000010 #define mod 1000000007 #define PI acos(-1.0) #define LL long long using namespace std; struct point { double x,y; }a[2010],p[4000010]; bool cmp(point a,point b) { if(a.x==b.x)return a.y<b.y; else return a.x<b.x; } int main() { int i,j,n,top=0; Si(n); for(i=0;i<n;i++) { Sd(a[i].x),Sd(a[i].y); } for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { p[top].x=(a[i].x+a[j].x)/2; p[top].y=(a[i].y+a[j].y)/2; top++; } } sort(p,p+top,cmp); LL ans=0; LL cnt=1; for(i=0;i<top;i++) { if(fabs(p[i].x-p[i+1].x)>=1e-6||fabs(p[i].y-p[i+1].y)>=1e-6) { ans+=cnt*(cnt-1)>>1; cnt=1; }else { cnt++; } } Pl(ans); return 0; }
相关文章推荐
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- codeforces 618C. Constellation
- Codeforces Round #265 (Div. 2)
- Codeforces #310 div2 C. Case of Matryoshkas
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers
- codeforces 16 Problem E fish
- Codeforces Round332 部分题解
- CodeForces 603A_Alternative Thinking (DP)
- CodeForces 602B_Approximating a Constant Range_DP
- Codeforces round #247 for Div. 2
- Codeforces Round #246 (Div. 2)
- Codeforces #264(div 2)D.Gargari and Permutations
- Codeforces Round #236 (Div. 2)------A,B
- codeforces 257 div2 B
- Codeforces Gym100571A Cursed Query