C. Watchmen

题目连接:

http://www.codeforces.com/contest/651/problem/C

Description

Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).

They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula .

The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.

Input

The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen.

Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109).

Some positions may coincide.

Output

Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.

Sample Input

3

1 1

7 5

1 5

Sample Output

2

Hint

题意

有n个点,然后让你算出有多少对点的欧几里得距离等于曼哈顿距离

题解:

平方之后,显然只要,只要(xi-xj)0或者(yi-yj)0就满足题意了

然后容斥一发,x相等+y相等-xy相等就好。

代码

#include<bits/stdc++.h>
using namespace std; map<int,long long>x;
map<int,long long>y;
map<pair<int,int>,long long>xy;
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int X,Y;
scanf("%d%d",&X,&Y);
x[X]++;
y[Y]++;
xy[make_pair(X,Y)]++;
}
map<int,long long>::iterator it;
long long ans = 0;
for(it=x.begin();it!=x.end();it++)
{
long long p = it->second;
ans+=(p*(p-1)/2);
}
for(it=y.begin();it!=y.end();it++)
{
long long p = it->second;
ans+=(p*(p-1)/2);
}
map<pair<int,int>,long long>::iterator it2;
for(it2=xy.begin();it2!=xy.end();it2++)
{
long long p = it2->second;
ans-=(p*(p-1)/2);
}
cout<<ans<<endl;
}

Codeforces Round #345 (Div. 1) A - Watchmen 容斥的更多相关文章

  1. Codeforces Round #345 (Div. 1) A. Watchmen

    A. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...

  2. Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点

    Watchmen 题意:有n (1 ≤ n ≤ 200 000) 个点,问有多少个点的开平方距离与横纵坐标的绝对值之差的和相等: 即 = |xi - xj| + |yi - yj|.(|xi|, |y ...

  3. Codeforces Round #345 (Div. 1) A. Watchmen (数学,map)

    题意:给你\(n\)个点,求这\(n\)个点中,曼哈顿距离和欧几里得距离相等的点对数. 题解: 不难发现,当两个点的曼哈顿距离等于欧几里得距离的时候它们的横坐标或者纵坐标至少有一个相同,可以在纸上画一 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #345 (Div. 2)

    DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...

  6. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

    A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  7. Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集

    题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...

  8. Codeforces Round #345 (Div. 2) C (multiset+pair )

    C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...

  9. Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集

    E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...

随机推荐

  1. flask_返回字节流错误

    # flask_返回字节流错误 def export_data(filename, fields, data, names=None, sheet='Sheet1'): # fields 为list ...

  2. ioctl( ) 函数

    ioctl( )函数 本函数影响由fd参数引用的一个打开的文件. #include<unistd.h> int ioctl( int fd, int request, .../* void ...

  3. 安全测试===burpsuit指南

    网址: https://www.gitbook.com/book/t0data/burpsuite/details 引子 刚接触web安全的时候,非常想找到一款集成型的渗透测试工具,找来找去,最终选择 ...

  4. 64_g2

    gettext-libs-0.19.8.1-9.fc26.x86_64.rpm 15-Mar-2017 14:15 305038 gf2x-1.1-9.fc26.i686.rpm 11-Feb-201 ...

  5. Microsoft .NET Native

    首页: https://msdn.microsoft.com/en-US/vstudio/dotnetnative

  6. js判断文件格式及大小

      //判断照片大小 function getPhotoSize(obj){     photoExt=obj.value.substr(obj.value.lastIndexOf(".&q ...

  7. Path Sum I&&II

      I Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...

  8. JavaSwing 版本的简单扫雷游戏

    JavaSwing 版本的简单扫雷游戏 一.扫雷游戏的基本规则 1.扫雷游戏分为初级.中级.高级和自定义四个级别. 单击游戏模式可以选择"初级"."中级".&q ...

  9. web资料收集

    Web安全资料:https://github.com/CHYbeta/Web-Security-Learning http://blog.pentestbegins.com/2017/07/21/ha ...

  10. thinkphp的where方法的使用

    1.Thinkphp中where()条件的使用 总是有人觉得,thinkphp的where()就是写我要进行增加.查询.修改.删除数据的条件,很简单的,其实我想告诉你,where()是写条件语句的,但 ...