Watchmen CodeForces - 650A
Watchmen CodeForces - 650A
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.
Examples
3
1 1
7 5
1 5
2
6
0 0
0 1
0 2
-1 1
0 1
1 1
11
Note
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.
题意:给出n个点的坐标(xi,yi);问有多少对点|xi-xj|+|yi-yj| == sqrt( (xi-xj)^2 + (yi-yj)^2 )。 注意:题中有些点的和重合的。
题解:map存存状态,加加减减就好了
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<stack>
#include<map>
#include<cstdlib>
#include <vector>
#include<queue>
using namespace std; #define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
const int maxn = 1e5+;
const int mod = 1e9+; map<ll,ll>mpx;
map<ll,ll>mpy;
map<pair<ll,ll>,ll>mp;
int main()
{
mpx.clear();
mpy.clear();
mp.clear();
int n;
ll a,b,ans=,num=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%lld %lld",&a,&b);
num+=mp[make_pair(a,b)];
mp[make_pair(a,b)]++;
ans+=mpx[a];
mpx[a]++;
ans+=mpy[b];
mpy[b]++;
//printf("%lld %lld\n",ans,num);
}
printf("%lld\n",ans-num);
return ;
}
Watchmen CodeForces - 650A的更多相关文章
- A. Watchmen(Codeforces 650A)
A. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...
- 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 Codeforces 650A Watchmen
题意:两点(x1,y1), (x2,y2)的曼哈顿距离=欧几里得距离 也就是:x1=x2或y1=y2,再删除重合点造成的重复计数即可. #include <stdio.h> #includ ...
- [刷题codeforces]650A.637A
650A Watchmen 637A Voting for Photos 点击查看原题 650A又是一个排序去重的问题,一定要注意数据范围用long long ,而且在写计算组合函数的时候注意也要用l ...
- Codeforces Round #345 (Div. 1) A - Watchmen 容斥
C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...
- 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 ...
- Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点
Watchmen 题意:有n (1 ≤ n ≤ 200 000) 个点,问有多少个点的开平方距离与横纵坐标的绝对值之差的和相等: 即 = |xi - xj| + |yi - yj|.(|xi|, |y ...
随机推荐
- FTP连接报530 User 用户名 cannot log in home directory inaccessible的解决方法
在server 2003新建ftp用户并开启IIS的Ftp功能之后,有时在连接这个ftp的时候会出现530 User 用户名 cannot log in home directory inaccess ...
- phpcms文件结构
主要目录部分 /admin 管理后台目录 -- /skin/ 后台样式 -- /templates/ 后台样式模板 /api api接口 /corpandresiz ...
- android 开发-ListView列表显示控件的实现
列表的显示需要三个元素: 1.ListVeiw 用来展示列表的View. 2.适配器 用来把数据映射到ListView上的中介. 3.数据 具体的将被映射的字符串,图片,或者基本组件. 根据列表 ...
- <Linux系统uname命令用法>
uname命令:操作系统信息的显示 uname 命令主要用于显示操作系统的信息,包括版本.平台的信息. 它的参数主要有以下: -a 显示全部信息 -s 显示内核名称 -n 显示主机名 -r 显示当前系 ...
- Elasticsearch在后台启动
Elasticsearch在linux下使用命令sh elasticsearch start,按键ctrl+c的时候程序就会stop掉,如何将程序在后台启动呢? 需要使用:./elasticsearc ...
- synchronized锁——8锁
前言 多线程是Java面试中最喜欢问的问题之一,有一篇公众号推文内容很详细,推荐看看 但凡面试官考“多线程”,一定会问这10个问题! 本文中仅对synchronized关键字的加锁进行一定分析 一.标 ...
- java8 api简介(一)
from https://www.aliyun.com/jiaocheng/785076.html 摘要:函数式编程详解:前言:现在有很多公司都用了jdk8,但是函数式编程也许没有用上,jdk8也提供 ...
- Teradata 认证系列 - 2. Teradata数据库总览
Teradata (以下简称TD) 总览本课的学习目标 描述Teradata数据库产品的功能 知晓支持的操作系统 描述Teradata的并行架构 解释线性可扩展性 列出Teradata DBA永远不需 ...
- 在wpf或winform关闭子窗口或对子窗口进行某个操作后刷新父窗口
父窗口: ///<summary> ///弹出窗口 ///</summary> ///<param name="sender"></pa ...
- 微信公众平台网页开发实战--3.利用JSSDK在网页中获取地理位置(HTML5+jQuery)
复制一份JSSDK环境,创建一份index.html文件,结构如图7.1所示. 图7.1 7.1节文件结构 在location.js中,封装“getLocation”接口,如下: 01 wxJSSD ...