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. CDN 内容分发网络

    第一步,HTML的文件引用:HTML的文件头(也有文件中,文件尾)那边常有其他文件引用,比如CSS以及JS的引用. 就以bootstrap常用的引用来举个栗子你常见的引用可能会是这样的: <he ...

  2. Flex使用总结

    最近做的项目因为对浏览器的兼容要求是IE10以上,所以大胆的使用了Flex布局,这里总结一些使用心得仅供参考. 一,Flex简单介绍 Flex是Flexible Box的缩写,意为”弹性布局”.任何一 ...

  3. Centos 自动删除日志文件的Shell代码

    #!/bin/bash # #判断文件夹内文件的大小,如果大于一定的数值,那么删除 # echo '判断文件夹内文件的大小,如果大于一定的数值,并且文件名称包含数字(年月日)的删除,那么删除' pat ...

  4. 【Oracle】重命名数据文件

    1)查看当前数据文件位置 SQL> select file_id,file_name,tablespace_name from dba_data_files; FILE_ID FILE_NAME ...

  5. VHDL之code structure

     1 VHDL units VHDL code is composed of at least 3 fundamental sections: 1) LIBRARY declarations: Con ...

  6. Eigen与Matlab语法及语义辞典

    Eigen为Matlab转换为C++提供了一个简单的语法级别的代码迁移工具. 对一些代码进行了扩充,以便程序由Matlab到Eigen的移植................... 参考链接:http: ...

  7. js-循环执行一个函数

    js里的两个内置函数:setInterval()与setTimeout()提供了定时的功能,前者是每隔几秒执行一次,后者是延迟一段时间执行一次.javascript 是一个单线程环境,定时并不是很准, ...

  8. golang入门-defer

    package main import "fmt" func main() { i := 5 tmap := make(map[string]int, 5) tmap[" ...

  9. Day6 函数和模块的使用

    函数和模块的使用 在讲解本章节的内容之前,我们先来研究一道数学题,请说出下面的方程有多少组正整数解. $$x_1 + x_2 + x_3 + x_4 = 8$$ 事实上,上面的问题等同于将8个苹果分成 ...

  10. 为类型定义取别名、环境变量、静态库与动态库(day03)

    一.为类型命名别名 struct node{ int num; struct node *next; }; typedef struct node node_t; node_t n; 使用typede ...