CodeForces 651C Watchmen map
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.
3
1 1
7 5
1 5
2
6
0 0
0 1
0 2
-1 1
0 1
1 1
11
题目大意:
给你很多组a,b 然后通过两种计算方法判断答案是否相同
1. |xi-xj|+|yi-yj|
2. sqrt((xi-xj)*(xi-xj) + (yi-yj)*(yi-yj))
题解:发现只有当xi = xj 或 yi = yj时答案相同
但同时要排除(xi,yi)=(xj,yj)的情况
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<int, int> mapx, mapy;
map<pair<int, int>, int> mapp;
int main()
{
int n, x, y;
scanf("%d", &n);
mapx.clear();
mapy.clear();
mapp.clear();
for (int k = ; k <= n; k++)
{
scanf("%d%d", &x, &y);
mapx[x]++;
mapy[y]++;
mapp[pair<int, int>(x, y)]++;
}
ll ans = ;
map<int, int>::iterator i;
int tem;
for (i = mapx.begin(); i != mapx.end(); i++)
{
tem = i->second;
ans += (ll)tem * (tem - ) / ;
}
for (i = mapy.begin(); i != mapy.end(); i++)
{
tem = i->second;
ans += (ll)tem * (tem - ) / ;
}
for (map<pair<int, int>, int>::iterator j = mapp.begin(); j != mapp.end(); j++)
{
tem = j->second;
ans -= (ll)tem * (tem - ) / ;
}
printf("%I64d\n", ans);
return ;
}
CodeForces 651C Watchmen map的更多相关文章
- codeforces 651C(map、去重)
题目链接:http://codeforces.com/contest/651/problem/C 思路:结果就是计算同一横坐标.纵坐标上有多少点,再减去可能重复的数量(用map,pair存一下就OK了 ...
- codeforces 651C Watchmen
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【模拟】
题意: 求欧几里得距离与曼哈顿距离相等的组数. 分析: 化简后得到xi=xj||yi=yj,即为求x相等 + y相等 - x与y均相等. 代码: #include<iostream> #i ...
- 【CodeForces - 651C 】Watchmen(map)
Watchmen 直接上中文 Descriptions: 钟表匠们的好基友马医生和蛋蛋现在要执行拯救表匠们的任务.在平面内一共有n个表匠,第i个表匠的位置为(xi, yi). 他们需要安排一个任务计划 ...
- 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 651C
Description Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg s ...
- codeforces Codeforces 650A Watchmen
题意:两点(x1,y1), (x2,y2)的曼哈顿距离=欧几里得距离 也就是:x1=x2或y1=y2,再删除重合点造成的重复计数即可. #include <stdio.h> #includ ...
随机推荐
- paper 77:[转载]ENDNOTE使用方法,常用!
一.简介 EndNote是一款用于海量文献管理和批量参考文献管理的工具软件,自问世起就成为科研界的必备武器.在前EndNote时代,文献复习阶段从各大数据库中搜集到的文献往往千头万绪.或重复或遗漏, ...
- sql 把一列的数据按逗号分隔转换成多行
ALTER proc [dbo].[ModifyWkCashAccountNo]asbeginset xact_abort onbegin transactiondeclare @errors int ...
- oracle 分区表的维护
1:添加分区: ALTER TABLE SALES ADD PARTITION P3 VALUES LESS THAN(TO_DATE('2003-06-01','YYYY-MM-DD')); SAL ...
- springmvc转发与重定向
摘自http://elf8848.iteye.com/blog/875830 (1)我在后台一个controller跳转到另一个controller,为什么有这种需求呢,是这样的.我有一个列表页面,然 ...
- android- Auto Monitor Logcat
启动模拟器的时候弹出窗体: 它实在询问你是否显示logcat视图以便显示此工作空间中的程序信息. 因为如何程序错误,可以从logcat中看到错误的原因,建议选择yes. 单击确定,你会发现多了一个Lo ...
- zw版【转发·台湾nvp系列例程】halcon与delphi系列例程
zw版[转发·台湾nvp系列例程]halcon与delphi系列例程 台湾nvp技术论坛,是目前halcon与delphi例程最多的网站,也是唯一成系列的, http://zip.nvp.com.tw ...
- Java中的get()和set()方法
对于JAVA初学者来说,set和get这两个方法似乎已经很熟悉了,这两个方法是JAVA变成中的基本用法,也是出现频率相当高的两个方法. 如果你对于这两个方法还有困惑甚至完全不知道这两个方法是做什么的, ...
- 161019、并发容器ConcurrentHashMap
java.util.concurrent.ConcurrentMap<K, V>一种是用读写锁实现Map的方法.此种方法看起来可以实现Map响应的功能,而且吞吐量也应该不错.但是通过前面对 ...
- 将txt文件数据转成bin文件.
之前用牛逼的绘图以及分析bmp的像素文件的方法, 整理出汉字编码从: 0x4E00到0x9FA5, (维基上说是9FD5, 完了, 回头再更新吧.) https://en.wikipedia.org/ ...
- 用Meta标签控制360浏览器默认极速模式打开自己的网站和正则表达式
在head标签中添加一行代码: <html><head><meta name="renderer" content="webkit|ie-c ...