CodeForces 651C
Description
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.
Sample Input
3
1 1
7 5
1 5
2
6
0 0
0 1
0 2
-1 1
0 1
1 1
11
Hint
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.
思路:把题目的两个公式同时平方,化简得只要xi=xj或者yi=yj,等式就会成立,暴力的话容易超时,学长当时给了题解,
用stl的map去写,后来自己也看了下,的确很好用
统计x相等的个数加上y相等的个数减去xy同时相等的个数,就是结果了
代码是学长给的,发现比网上的一些简单多了
#include <iostream>
#include <map>
using namespace std;
int main()
{
int n;
while (cin>>n)
{
map<int,int> mx;
map<int,int> my;
map<pair<int,int>,int>mxy;
long long ans = ;
for (int i=;i<n;++i)
{
int x,y;
cin>>x>>y;
ans += mx[x]++;
ans += my[y]++;
ans -= mxy[make_pair(x,y)]++;
}
cout<<ans<<endl;
}
}
CodeForces 651C的更多相关文章
- codeforces 651C(map、去重)
题目链接:http://codeforces.com/contest/651/problem/C 思路:结果就是计算同一横坐标.纵坐标上有多少点,再减去可能重复的数量(用map,pair存一下就OK了 ...
- CodeForces 651C Watchmen map
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...
- 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 直接上中文 Descriptions: 钟表匠们的好基友马医生和蛋蛋现在要执行拯救表匠们的任务.在平面内一共有n个表匠,第i个表匠的位置为(xi, yi). 他们需要安排一个任务计划 ...
- Codeforces 651C Watchmen【模拟】
题意: 求欧几里得距离与曼哈顿距离相等的组数. 分析: 化简后得到xi=xj||yi=yj,即为求x相等 + y相等 - x与y均相等. 代码: #include<iostream> #i ...
- CodeForces - 651C Watchmen (去重)
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...
- Codeforces Round #345(Div. 2)-651A.水题 651B.。。。 651C.去重操作 真是让人头大
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- [转]Java web 开发 获取用户ip
如果通过了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP值,那么真正的用户端的真实IP则是取X-Forwarded-For中第一个非unknown的有效IP字符串. pu ...
- 富文本wangEditor的批量激活
最近项目中使用了wangEditor这个轻量级的富文本框,由于需求是一个页面中会有多个富文本框同时激活,所以写了个批量激活的jquery方法,分享一下 // 激活富文本框 var wangEditor ...
- 【PLSQL】游标
Oracle中的SQL在执行时需要分配一块内存区域,这块内存区域叫做上下文区. 上下文区中记录了SQL语句的处理信息,这些信息包括:查询返回的数据行.查询所处理的数据的行号.指向共享池中的已分析的SQ ...
- 乐乎共享wifi充电宝项目
- Caffe: Vs13添加CUDA支持
1. 右键工程 点击:Building Dependency 右击:Build Customizations 点击选项:CUDA 7.5 2.添加C++依赖: cudart.lib kernel32 ...
- QT-Creator+SDK+编译器+自定义配置
QT4.8的软件曾经耗费巨大的功夫进行构建,不舍得扔掉!重新安装Qt4.8版本 1.安装qt-creator 安装qt-creator-win-opensource-2.4.0.exe版本,不建议使用 ...
- HDU_1850_nim游戏
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32 ...
- Apex语言(六)数组
1.数组 数组能保存多个数据,每一个数据称为数组元素,元素的个数称为数组的长度. 数组元素的类型必须相同,元素的类型就是数组的类型. 数组元素在数组中都有一个编号,称为数组下标.下标从0开始编号,通过 ...
- spring cloud(五) hystrix
开启feign 熔断 hystrix 整合hystrix-dashboard监控面板 1. 服务调用者boot工程 pom引入依赖 <!-- hystrix-dashboard 监控依赖 ...
- 【转】VMWare vCenter 6.0安装配置
版权声明: 专注于"GIS+"前沿技术的研究与交流,将云计算技术.大数据技术.容器技术.物联网与GIS进行深度融合,探讨"GIS+"技术和行业解决方案:文章允许 ...