codeforces--650A Watchmen(math)

本文介绍了一道关于计算几何题目CF650A的解题思路与代码实现。通过对坐标进行分析,利用哈希表统计特定条件下的坐标对数量,最终计算出满足条件的坐标对总数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CF 650A

题意

|xixj|+|yiyj|=(xixj)2+(yiyj)2 的个数。

题解

显然,只有 xi==xj 或者 yi==yj 的时候才相等。

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
map<int, int> px, py;
map<pair<int, int>, int> ps;

int main()
{
    int n, x, y;

    cin >> n;
    for(int i = 0; i < n; ++i){
        scanf("%d %d", &x, &y);
        px[x]++, py[y]++;
        ps[make_pair(x, y)]++;
    }
    ll ans = 0;
    for(auto &it: px){
        int cnt = it.second;
        ans += (ll)cnt * (cnt - 1) / 2;
    }
    for(auto &it: py){
        int cnt = it.second;
        ans += (ll)cnt * (cnt - 1) / 2;
    }
    ll samepair = 0;
    for(auto &it: ps){
        int cnt = it.second;
        if(cnt > 1) samepair += (ll)cnt * (cnt - 1) / 2;
    }
    cout << ans - samepair << endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值