codefroces 650A. Watchmen
3 seconds
256 megabytes
standard input
standard output
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.
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.
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.
3
1 1
7 5
1 5
2
6
0 0
0 1
0 2
-1 1
0 1
1 1
11
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.
加上相同的,减去重复的
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
map<ll,ll>ans,pos;
map<pair<ll,ll>,ll>inf;
ll x,y,n,cnt=;
cin>>n;
while(n--)
{
cin>>x>>y;
cnt+=ans[x]++;
cnt+=pos[y]++;
cnt-=inf[make_pair(x,y)]++;//减去重复的
}
cout<<cnt<<endl;
}
codefroces 650A. Watchmen的更多相关文章
- Codeforces 650A Watchmen
传送门 time limit per test 3 seconds memory limit per test 256 megabytes input standard input output st ...
- codeforces Codeforces 650A Watchmen
题意:两点(x1,y1), (x2,y2)的曼哈顿距离=欧几里得距离 也就是:x1=x2或y1=y2,再删除重合点造成的重复计数即可. #include <stdio.h> #includ ...
- (水题)Codeforces - 650A - Watchmen
http://codeforces.com/contest/650/problem/A 一开始想了很久都没有考虑到重复点的影响,解欧拉距离和曼哈顿距离相等可以得到 $x_i=x_j$ 或 $y_i=y ...
- Watchmen CodeForces - 650A
Watchmen CodeForces - 650A Watchmen are in a danger and Doctor Manhattan together with his friend Da ...
- [刷题codeforces]650A.637A
650A Watchmen 637A Voting for Photos 点击查看原题 650A又是一个排序去重的问题,一定要注意数据范围用long long ,而且在写计算组合函数的时候注意也要用l ...
- Codeforces数据结构(水题)小结
最近在使用codeblock,所以就先刷一些水题上上手 使用codeblock遇到的问题 1.无法进行编译-------从setting中的编译器设置中配置编译器 2.建立cpp后无法调试------ ...
- A. Watchmen(Codeforces 650A)
A. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...
- 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 ...
- CodeForces 651C Watchmen map
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...
随机推荐
- 基于json数据格式实现的简单数据库——jsonDB
已在github上建立项目:https://github.com/ThinkerCodeChina/jsonDB /** +-------------------------------------- ...
- 大浪淘沙,JSP终将死去
首先讲明,我不是标题党. 这纯属我个人的意见.勿喷. 先来讲讲JSP是怎么出现的吧. 在早期的WEB中,JS.CSS远未成熟,技术慷慨向并不明白!因为前端语言的匮乏.各家大公司都推出基于后端的模板语言 ...
- 物理读之LRU(近期最少被使用)的深入解析
转载请注明出处: http://blog.csdn.net/guoyjoe/article/details/38264883 一组LRU链表包含LRU主链.LRU辅助链.LRUW主链,LRUW辅助链, ...
- MFC,C++,VC++,VS2010 之间究竟是什么关系
C++是在C语言的基础上发展而来的面向对象的一种语言: MFC是基于C++类的窗口开发工具,内含大量的基类.降低编程人员的工作量: VC++是一种开发工具. VS2010是更高版本号的开发工具,功能强 ...
- Opencv(3.0.0beta)+Python(2.7.8 64bit) 简单具体,一遍成功
看到非常多配置的文章,都没法正常走完流程 使用到的资源,都是今天为止最新的: python-2.7.8.amd64.msi opencv-3.0.0-beta.exe numpy-MKL-1.9.1. ...
- [javase学习笔记]-6.7 封装
这一节我们学习面向对象中的第一个特性,封装(encapsulation) 封装:是指隐藏对象的发生和实现细节,仅对外提供公共訪问方式. 那么什么是隐藏对象的实现细节? 我们来举例学习. 比方我们来定义 ...
- List of content management systems
https://en.wikipedia.org/wiki/List_of_content_management_systems Microsoft ASP.NET Name Platform Sup ...
- PostgreSQL Replication之第七章 理解Linux高可用(4)
7.4 术语与概念 一组计算机被称为集群.集群内的一台计算机被称为一个节点. 当集群内的节点数量是 N (2,,3,等.) ,那么我们讨论一个N节点的集群. 高可用性软件,传输层和集群管理层都运行于每 ...
- php八大设计模式之职责链模式
当发生一种事情时,我们需要要对应职责的事物去处理对应的事情. 或者去找最近的类(就是级别最低的)去解决,如果解决不了就顺着往上找职责更高的,直到解决为止. 注意:一定是要有一个职责最高的类,否则会有问 ...
- HDU-1032 The 3n+1 problem 模拟问题(水题)
题目链接:https://cn.vjudge.net/problem/HDU-1032 水题 代码 #include <cstdio> #include <algorithm> ...