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

Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11

Hint

In the first sample, the distance between watchman 1 and watchman 2 is equal to

|1 - 7| + |1 - 5| = 10 for Doctor Manhattan and

for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will

calculate the same distances.

思路:把题目的两个公式同时平方,化简得只要xi=xj或者yi=yj,等式就会成立,暴力的话容易超时,学长当时给了题解,

用stl的map去写,后来自己也看了下,的确很好用

统计x相等的个数加上y相等的个数减去xy同时相等的个数,就是结果了

代码是学长给的,发现比网上的一些简单多了

 #include <iostream>
#include <map>
using namespace std;
int main()
{
int n;
while (cin>>n)
{
map<int,int> mx;
map<int,int> my;
map<pair<int,int>,int>mxy;
long long ans = ;
for (int i=;i<n;++i)
{
int x,y;
cin>>x>>y;
ans += mx[x]++;
ans += my[y]++;
ans -= mxy[make_pair(x,y)]++;
}
cout<<ans<<endl;
}
}

CodeForces 651C的更多相关文章

  1. codeforces 651C(map、去重)

    题目链接:http://codeforces.com/contest/651/problem/C 思路:结果就是计算同一横坐标.纵坐标上有多少点,再减去可能重复的数量(用map,pair存一下就OK了 ...

  2. CodeForces 651C Watchmen map

    Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...

  3. codeforces 651C Watchmen

    Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...

  4. 【CodeForces - 651C 】Watchmen(map)

    Watchmen 直接上中文 Descriptions: 钟表匠们的好基友马医生和蛋蛋现在要执行拯救表匠们的任务.在平面内一共有n个表匠,第i个表匠的位置为(xi, yi). 他们需要安排一个任务计划 ...

  5. Codeforces 651C Watchmen【模拟】

    题意: 求欧几里得距离与曼哈顿距离相等的组数. 分析: 化简后得到xi=xj||yi=yj,即为求x相等 + y相等 - x与y均相等. 代码: #include<iostream> #i ...

  6. CodeForces - 651C Watchmen (去重)

    Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...

  7. Codeforces Round #345(Div. 2)-651A.水题 651B.。。。 651C.去重操作 真是让人头大

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

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. Android之通过配置Flavor实现一个项目打包成多个apk

    最近我老大问我一个问题,说Android可不可以像iOS那样,通过target对项目进行管理啊.老大提这个问题也是正常的,我公司的主要是帮别的公司做硬件定制的,每定制一个硬件就要定制一个APP,但是很 ...

  2. JavaScript中比较运算符的使用

    比较运算符的基本操作过程是:首先对操作数进行比较,这个操作数可以是数字也可以是字符串,然后返回一个布尔值true或false. 在JavaScript中常用的比较运算符如下表所示. 例如,某商场店庆搞 ...

  3. SLAM:飞行机器人的参数解析-分类

    在水电站存在的山区,公路运输效率极低,盘山公路绕行消耗大量时间,使用飞行机器人进行运输是合适的选择. 实现一位长辈在山区飞行的愿望,任重而道远 常见飞行机器人的参数解析:解读飞行机器人的基本类型及技术 ...

  4. Java接口和Java抽象类的认识

    在没有好好地研习面向对象设计的设计模式之前,我对Java接口和Java抽象类的认识还是很模糊,很不可理解. 刚学Java语言时,就很难理解为什么要有接口这个概念,虽说是可以实现所谓的多继承,可一个只有 ...

  5. RBM(受限玻尔兹曼机)和深层信念网络(Deep Brief Network)

    目录: 一.RBM 二.Deep Brief Network 三.Deep Autoencoder 一.RBM 1.定义[无监督学习] RBM记住三个要诀:1)两层结构图,可视层和隐藏层:[没输出层] ...

  6. eas之利用KDTableHelper批量填充数据

    // 下述代码将创建一个KDTable,并指定列名.表头单元格的显示值.和表体数据KDTable table = new KDTable();String [] columnKeys = new St ...

  7. NOIP2012 DAY2 T2借教室

    题目描述 在大学期间,经常需要租借教室.大到院系举办活动,小到学习小组自习讨论,都需要向学校申请借教室.教室的大小功能不同,借教室人的身份不同,借教室的手续也不一样. 面对海量租借教室的信息,我们自然 ...

  8. java链接linux服务器,命令操作

    1.本地读取linux文件,即在Windows上链接外部linux package com.common.utils; import java.io.BufferedReader; import ja ...

  9. html_entity_decode()、空格、&nbsp; 乱码问题

    普通 ASCII 码空格为 32,但是浏览器会对普通空格进行自动归并,也就是如果你输入10个 0x20 的空格在HTML页面里面,可能会被合并成一个空格. 如果想要一致的呈现多个空格,就要用到 编码标 ...

  10. 继续聊WPF

    下面看一个Tick控件的例子,这只是演示,Tick单独使用没有意义. <TickBar Height="15" Width="180" Ticks=&qu ...