Given n points on the XY plane, count how many regular rectangles is formed. A rectangle is regular if and only if it sides is all parallel to the axis.
Input
The. RST line contains the number of tests T (1≤T≤10). Each case contains a single line with a
Positive integer n (1≤n≤5000), the number of points. There is n lines follow, each line contains 2
integers x, y (≤x, y≤109
) indicating the coordinates of a point.
Output
For each test case, print the case number and a single integer, the number of regular rectangles found.
Sample Input
2
5
0 0
2 0
0 2
2 2
1 1
3
0 0
0 30
0 900
Sample Output
Case 1:1
Case 2:0
Test Instructions : give you n points, ask you how many of these points can form a rectangle parallel to the length and axis
the puzzle: According to the X sort, in the y-axis parallel, choose a different line combination, to meet the two y-axis point equality is a kind, for a bunch of equal we use the combination of the number is good
//Meek///#include<bits/stdc++.h>#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<cstring>#include<algorithm>using namespacestd; typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#definePB Push_back#defineFi first#defineSe Second#defineMP Make_pairConst intn=5005;Constll INF = 1ll<< A;Const intINF =1<< to;Const intMod=1000000007;Const intM =1000000;structss{intx, y;} A[n],p[n*N];intCNT;intCMP (ss S1,ss S2) {if(s1.x = = s2.x)returns1.y<s2.y; returns1.x<s2.x;}voidinit () {CNT=0; mem (p);} ll solve () {ll ans=0; for(inti =0; I <CNT;) { intnow = i+1; while(p[i].x = = p[now].x && p[i].y = = p[now].y) now++; ll c= Now-i; if(c>=2) ans + = c* (C-1)/2; I=Now ; } returnans;}intMain () {intT,n,x,y,cas =1; scanf ("%d",&T); while(t--) {init (); scanf ("%d",&N); for(intI=1; i<=n;i++) {scanf ("%d%d",&x,&y); a[i].x=x; A[i].y=y; } sort (A+1, a+n+1, CMP); CNT=0; for(intI=1; i<=n;i++) { for(intj=i+1; j<=n;j++) { if(a[i].x! =a[j].x) { Break; } p[cnt].x=a[i].y; P[cnt].y=a[j].y; CNT++; }} printf ("Case %d:", cas++); Sort (p,p+cnt,cmp); printf ("%lld\n", Solve ()); } return 0;}
Code
UVA 10574-counting rectangles Count