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 ...
随机推荐
- 夺命雷公狗mongodb之----mongodb---3---比较操作符
$lt < less than 小于 $lte <= less than and equal 小于等于 $gt > greater than 大于 $gte ...
- clock gating and PLL
一个gating的clock是指:clock network除了包含inverter和buffer外,还有其他logic. PrimeTime会自动的对gating input进行setup和hold ...
- Multi-voltage和power gating的实现
power domain:一个逻辑的集合体,包含power supply的一些信息.建立在FE. voltage area:chip上的一块物理区域.可以看作power domain的物理实现. Le ...
- DDR(一)
P-Bank:计算机早期的一个概念.目的:匹配内存芯片和CPU芯片的数据总线的宽度.方法:并联多个内存模块. L-Bank:对内部存储阵列的分割,避免寻址冲突,提高内存效率.通过ba信号选择bank, ...
- delphi 读取excel 两种方法
http://www.cnblogs.com/ywangzi/archive/2012/09/27/2705894.html 两种方法,一是用ADO连接,问题是Excel文件内容要规则,二是用OLE打 ...
- ThinkPHP讲解(四)——视图
本次讲解主要以<ThinkPHP开发手册>中“模板”一章中讲解为主 在MainController.class.php中新建一个操作方法Test() namespace Home\Cont ...
- iOS - 代码查看控制台打印内存使用情况:
1.先导入: #import <mach/mach.h> 2.写此方法.单位为兆(M). void report_memory(void) { struct task_basic_info ...
- 继承(引用~析构~virtual)
[1]程序1 #include <iostream> using namespace std; class Base { private: int m_nBase; public: Bas ...
- android 项目学习随笔七(ViewPagerIndicator与ViewPager)
1.ViewPagerIndicator https://github.com/JakeWharton/ViewPagerIndicator package com.viewpagerindicato ...
- innodb的锁时间
观察innodb的锁时间,需要关注: mysqladmin extended-status -r -i 1 -uroot | grep "Innodb_row_lock_time" ...