问题 J: 直角三角形

 

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

在平面直角坐标系上有N个点。
编写程序,统计出这N个点能构成多少个两直角边分别平行于坐标轴的直角三角形。

输入

输入共有两行:
第1行:输入一个整数N,(3≤N≤500,000);
第2行到N+1行:每行两个正整数X,Y(1≤X,Y≤500,000),代表点的坐标。

输出

输出只有一行,
输出直角三角形的个数。

样例输入 Copy

【样例1】
3
4 2
2 1
1 2
【样例2】
6
10 10
20 10
10 20
20 20
30 20
30 30

样例输出 Copy

【样例1】
0
【样例2】
8

提示

对于全部40%的数据,保证N≤100;
对于全部70%的数据,保证N≤10,000;
对于全部的数据,保证N≤500,000;
 
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e6+100;
struct node{
    int x,y;
}a[maxn];
int xx[maxn];
int yy[maxn];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].x>>a[i].y;
        xx[a[i].x]++;
        yy[a[i].y]++;
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=1ll*(xx[a[i].x]-1)*(yy[a[i].y]-1); 
    }
    cout<<ans<<endl;
}
原文地址:https://www.cnblogs.com/lipu123/p/14017711.html