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 ...
随机推荐
- Day1下午
T1 暴力50分 排A和B X,不用考虑X 用数组80分, 权值线段树.平衡树100, 一个函数? T2 打表 dp logn+1,+ 搜索,dp? txt..... T3 30分暴力和尽量均 ...
- SpringMVC 返回自定义属性名
SpringMVC 返回的属性名默认是小写驼峰形式的实体对象中的属性名,如 userID 属性名它会返回 userId. 如果接口方式之前已经定下来,这样前端按原来的方式取数据会读取失败的,那有没有方 ...
- 程序运行的cpu时间
time.clock() 测量CPU时间,比较精准,通过比较程序运行前后的CPU时间差,得出程序运行的CPU时间.
- C# 连接 postgres失败
小程序完成了,要发布到客户的服务器上: 我的测试机:win10 64 数据库:PG9.6.5 64 客户服务器:win7 32 数据库: ...
- JS中关于clientWidth offsetWidth scrollWidth 等的区别
网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...
- FusionCharts使用JavaScript渲染图表(不用Flash)
FusionCharts可以让用户只使用JavaScript建立图表(而不是使用Flash),只需要添加另一行代码,如下所示: FusionCharts.setCurrentRenderer('jav ...
- jQuery遍历Table表格的行和列
遍历Table表格的行和列,在开发中比较常用的功能,特别是前端开发人员,不多说,直接上代码,下面代码只是弹出第一列字段,请各位自己根据需求修改和扩展! <!DOCTYPE html PUBLIC ...
- 【Linux/Ubuntu学习 10】unbuntu 下 eclipse 中文乱码的解决
wangdd@wdd-pc:~$ gedit /var/lib/locales/supported.d/local 添加: zh_CN.GBK GBK zh_CN.GB2312 GB2312 终端执行 ...
- spring mvc 的理解
1.Spring MVC是什么? Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基 ...
- mybat-大文件的存取
在mybatis中存储大文件可以直接存 取的时候取出来的是二进制 1.在实体类中添加大文本和图片 package com.java1234.model; public class Student { ...