设为首页 加入收藏

TOP

TOJ Right Triangles II
2014-11-23 19:56:01 来源: 作者: 【 】 浏览:9
Tags:TOJ Right Triangles

Total Submit: 53 Accepted: 14
Description


N points are placed in the coordinate plane.
Write a program that calculates how many ways we can choose three points so that they form a right triangle with legs parallel to the coordinate axes.
A right triangle has one 90-degree internal angle. The legs of a right triangle are its two shorter sides.


Input


The first line of input contains the integer N (3 ≤ N ≤ 100 000), the number of points.
Each of the following N lines contains two integers X and Y (1 ≤ X, Y ≤ 100 000), the coordinates of one point.
No pair of points will share the same pair of coordinates.


Output


Output the number of triangles.


Sample Input


3
4 2
2 1
1 3

Sample Output


0

Uploader

crq

#include 
#include 
#include 
#include 
#include 
using namespace std;

const int maxn = 100008;

vector<__int64> x[maxn];
__int64 y[maxn];

int n;

void work() {
    __int64 i, j;
    __int64 cnt = 0;
    for(i = 1; i < maxn; i++) {//maxn --> n !!!
        __int64 Size = x[i].size();
        if(Size <= 1) continue;
        for(j = 0; j < Size; j++) {
            __int64 id = x[i][j];
            if(y[id] > 0)
                cnt += (Size - 1) * (y[id] - 1);
        }
    }
    printf("%I64d\n", cnt);
}

void init() {
    int i;
    for(i = 0; i < maxn; i++) {
        x[i].clear();
        y[i] = 0;
    }
}

int main()
{
    int i;
    int dx, dy;
    while(scanf("%d", &n) != EOF) {
        init();
        for(i = 0; i < n; i++) {
            scanf("%d%d", &dx, &dy);
            x[dx].push_back(dy);
            y[dy]++;
        }
        work();
    }
    return 0;
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇TOJ 4224 Cryptologist 下一篇矩形子数组的最大和

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C语言中,“指针”用 (2025-12-26 15:20:18)
·在c语言的指针运算中 (2025-12-26 15:20:15)
·C语言-函数指针与函 (2025-12-26 15:20:12)
·求navicat for mysql (2025-12-26 13:21:33)
·有哪位大哥推荐一下m (2025-12-26 13:21:30)