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 ...
随机推荐
- Windows phone开发数据绑定系列(1)--了解数据绑定
(部分内容参考MSDN文档) 数据绑定是在应用程序UI与业务逻辑之间建立连接的过程.通过数据绑定的方式实现了后台数据和前台UI元素的关联, 为用户提供了更好地交互体验. 数据绑定一般有以下几种体现方式 ...
- MEF编程模型
Contract由Contract name和Contract type组成,Contract两个参数可以省略可以implicit也可以explicit,implicit时name和type会自动推断 ...
- easyui combobox的增加全选解决方案
1.解决方案背景: 项目中偶然需要用到easyui的combobox的组件,但是本组件自己没有包含全选的api事件.搜索了一些解决方案,但是不是很符合,后来发现是因为所使用的版本不一致所导致的.项 ...
- 【Hexo】本地local4000打不开解决方法
错误:Cannot GET /spadesq.github.io/ (注:spadesq.github.io是原来放hexo文件夹的名字) 由于我后来把hexo文件夹搬迁到别处,但我发现打开本地,地址 ...
- jq 获取表单所有数据
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- js-循环执行一个函数
js里的两个内置函数:setInterval()与setTimeout()提供了定时的功能,前者是每隔几秒执行一次,后者是延迟一段时间执行一次.javascript 是一个单线程环境,定时并不是很准, ...
- 有关微信小程序
每个页面都要在app.json中配置 "pages": [ "pages/index/index", "pages/list/list", ...
- eas之网络互斥功能示手工控制
public void doMutexService() { IMutexServiceControl mutex = MutexServiceControlFactory.get ...
- 【剑指Offer】45、扑克牌顺子
题目描述: LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张^_^)...他随机从中抽出了5张牌,想测测自己的手气,看看能不能抽到顺子,如果抽到 ...
- 【剑指Offer】32、把数组排成最小的数
题目描述: 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323. ...