A. Watchmen
来源:互联网 发布:网络名誉侵权案例分析 编辑:程序博客网 时间:2024/06/05 19:05
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.
31 17 51 5
2
60 00 10 2-1 10 11 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.
解题说明:曼哈顿距离和两点间的距离相等,A(x1,y1) ,B(X2,Y2);|x1-x2|+|y1-y2|=sqrt((x1-x2)^2+(y1-y2)^2);画个三角形你可以发现曼哈顿距离就是两直角边的和,而两点的距离为斜边那么当且x1==x2||y1==y2;这两种距离相等。那么只要找x1==x2||y1==y2,开个数组记录各个x的种类及其个数,y的种类和个数,c[x],b[y],由于x和y的数值比较大所以离散化下可以。
#include<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>#include <map>using namespace std;map<int,int>mp1,mp2;map<pair<int,int>,int>mp;int n,i,x,y;long long ans;int main(){scanf("%d",&n);for(i=1;i<=n;i++){scanf("%d%d",&x,&y);ans+=mp1[x]++;ans+=mp2[y]++;ans-=mp[make_pair(x,y)]++;}printf("%I64d\n",ans);}
- A. Watchmen
- 650A.Watchmen
- CF 650A Watchmen
- CodeForces 650A Watchmen
- Watchmen(Codeforces 650A)
- codeforces 650A Watchmen 【数学】
- codeforces--650A Watchmen(math)
- Codeforces 650A Watchmen(数学,算法优化)
- Codeforces 650A Watchmen 【数学 + 二分】
- Codeforces #345 div1 A. Watchmen 数学
- 【1】【组合数学】CodeForces 650A Watchmen
- CodeForces - 650A Watchmen (握手定理)
- CodeForces 650 A.Watchmen(map)
- Codeforces Round #345 (Div. 1) & CodeForces 650A Watchmen
- Codeforces650A Watchmen
- WATCHMEN 守望者,好看。
- Codeforces 651C - Watchmen
- CodeForces 651 C Watchmen
- STM32工程模板简单套用教程(Keil MDK)
- Android系统手机为什么卡?
- 虚拟Python环境——virtualenv
- 创建主键时报错:ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it mus
- jar4
- A. Watchmen
- Android中管理多个Fragment的最佳实践,完美解决保存状态与重影问题(转)
- Number Triangle
- java中的容器collection及其常用的子接口
- java多线程——监视锁(monitor)
- HDU 1232
- Java文件上传的两种方式
- 欢迎使用CSDN-markdown编辑器
- android6.0的SDK不能使用httpClient解决方法