CodeForces - 651C Watchmen (去重)
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.
思路:结果就是计算同一横坐标、纵坐标上有多少点,再减去可能重复的数量(用map,pair存一下)
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <map>
using namespace std;
#define ll long long
ll a,b;
map<ll,ll> mp1;
map<ll,ll> mp2;
map< pair<ll,ll>,ll> mp;
int main()
{
int n,m;
while(scanf("%d",&n)!=EOF){
ll ans=,num=;
mp1.clear();
mp2.clear();
mp.clear();
for(int i=;i<=n;i++){
scanf("%lld%lld",&a,&b);
num+=mp[make_pair(a,b)];
mp[make_pair(a,b)]++;
if(mp1.find(a)==mp1.end())
mp1[a]=;
else {
ans+=mp1[a];
mp1[a]++;
}
if(mp2.find(b)==mp2.end())
mp2[b]=;
else {
ans+=mp2[b];
mp2[b]++;
}
}
printf("%lld",(ll)ans-num);
}
return ;
}
CodeForces - 651C Watchmen (去重)的更多相关文章
- codeforces 651C Watchmen
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...
- CodeForces 651C Watchmen map
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...
- Codeforces 651C Watchmen【模拟】
题意: 求欧几里得距离与曼哈顿距离相等的组数. 分析: 化简后得到xi=xj||yi=yj,即为求x相等 + y相等 - x与y均相等. 代码: #include<iostream> #i ...
- codeforces 651C(map、去重)
题目链接:http://codeforces.com/contest/651/problem/C 思路:结果就是计算同一横坐标.纵坐标上有多少点,再减去可能重复的数量(用map,pair存一下就OK了 ...
- 【CodeForces - 651C 】Watchmen(map)
Watchmen 直接上中文 Descriptions: 钟表匠们的好基友马医生和蛋蛋现在要执行拯救表匠们的任务.在平面内一共有n个表匠,第i个表匠的位置为(xi, yi). 他们需要安排一个任务计划 ...
- Codeforces 650A Watchmen
传送门 time limit per test 3 seconds memory limit per test 256 megabytes input standard input output st ...
- (水题)Codeforces - 650A - Watchmen
http://codeforces.com/contest/650/problem/A 一开始想了很久都没有考虑到重复点的影响,解欧拉距离和曼哈顿距离相等可以得到 $x_i=x_j$ 或 $y_i=y ...
- CodeForces 651C
Description Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg s ...
- codeforces Codeforces 650A Watchmen
题意:两点(x1,y1), (x2,y2)的曼哈顿距离=欧几里得距离 也就是:x1=x2或y1=y2,再删除重合点造成的重复计数即可. #include <stdio.h> #includ ...
随机推荐
- linux学习--1. 文件系统
文件目录结构 闲话篇: linux我也是最近才开始学,写随笔是为分享学习经验的同时也留着供自己以后来参考.因为linux一切皆文件的基本哲学思想.所以我决定从文件目录开始写. 正文: 首先linux文 ...
- jvm 内存结构
jvm 内存结构 graph TB A(jvm)-->E(类加载器系统) A-->B(运行时数据区) A-->D(本地库接口) A-->C(执行引擎) B-->虚拟机栈 ...
- Android9.0 Settings 修改踩坑记录
问题现象 上图展示的很清楚,当系统语言为中文时,PreferenceScreen 中的折叠项 summary 描述重复显示的 bug,系统语言为英文时正常. 修改历程 先搜索 当前显示了 字符串,还真 ...
- RabbitMQ安装(发生系统错误5。拒绝访问。发生系统错误1067。进程意外终止。)
RabbitMQ安装步骤(windows) 1.RabbitMQ建立在强大的Erlang OTP平台上,因此我们首先需要安装Erlang. 2.接下来安装RabbitMQ服务rabbitmq-serv ...
- kettle:The tablename is not defined (empty)
报错误The tablename is not defined (empty) 去掉表输出中的"表分区数据"
- Redis主从结构主节点执行写入后wait命令对性能的影响
这里的Redis主从结构可以是简单的主从,sentinel,redis cluster中的主从等. wait命令的作用:此命令将阻塞当前客户端,直到当前Session连接(主节点上)所有的写命令都被传 ...
- RHEL7开机不能正常进入系统(图形化界面)
今天在重启RHEL7的虚拟机后一直无法正常开机,一直提示输入管理员密码,如下图所示: 输入密码后进入命令行模式,经排查出现此现象的问题是在挂载银盘的时候文件格式写错,在格式化硬盘的时候格式化的是xfs ...
- PHP0019:PHP 图像验证码 、图像水印效果 、 生成缩约图
- Docker Compose 启动mysql,redis,rabbitmq
这里使用的centos7,首先切换到root. sudo -s 首先去设置下载镜像,否则下载这三个东西要很久,而且可能失败. vim /etc/docker/daemon.json 内容如下: { & ...
- 开始Python之旅
2019/11/22,今天是个好日子!非常高兴笔者的博客申请得到通过,让本人有幸成为博客园的一份子! 本人是一枚自然语言处理的爱好者,所用到的语言工具就是python,因此笔者的博客内容主要关乎pyt ...