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 ...
随机推荐
- Calculation
定义一个Strategy接口,其中定义一个方法,用于计算 using System; using System.Collections.Generic; using System.Linq; usin ...
- (转)SQL对Xml字段的操作
T-Sql操作Xml数据 一.前言 SQL Server 2005 引入了一种称为 XML 的本机数据类型.用户可以创建这样的表,它在关系列之外还有一个或多个 XML 类型的列:此外,还允许带有变量和 ...
- IIS 浏览aspx页面出现 无法显示 XML 页
问题: 无法显示 XML 页. 使用 XSL 样式表无法查看 XML 输入.请更正错误然后单击 刷新按钮,或以后重试. 名称以无效字符开头.处理资源 'http://192.168.1.254:808 ...
- NOIP200902分数线划定
NOIP200902分数线划定 描述 世博会志愿者的选拔工作正在 A 市如火如荼的进行.为了选拔最合适的人才,A 市对所有报名的选手进行了笔试,笔试分数达到面试分数线的选手方可进入面试.面试分数线根据 ...
- android 应用架构随笔三(ListView)
import java.util.ArrayList; import java.util.List; import com.heima.googleplay.holder.BaseHolder; im ...
- android 学习随笔二十三(动画:Fragment )
Fragment * 用途:在一个Activity里切换界面,切换界面时只切换Fragment里面的内容 * 在一个Activity中切换多个界面,每个界面就是一个Fragment* Fragmnen ...
- NXP QN9020
NXP的这个BLE蓝牙方案也很有趣, 一起研究. 这个函数在app_gpa_task.c里面 ***************************************************** ...
- LUA之面向对象
Account = { balance=0, withdraw = function (self, v) self.balance = self.balance - v end } function ...
- JVM学习笔记(二)------Java代码编译和执行的整个过程【转】
转自:http://blog.csdn.net/cutesource/article/details/5904542 版权声明:本文为博主原创文章,未经博主允许不得转载. Java代码编译是由Java ...
- array DEMO
[xiluhua@vm-xiluhua][~]$ declare -a array #申明数组 [xiluhua@vm-xiluhua][~]$ array=("a" " ...