Codeforces Round #345 (Div. 2) C (multiset+pair )
3 seconds
256 megabytes
standard input
standard output
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
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.
题意: n个点 分别给出x,y坐标
两种两点的计算方式 |xi - xj| + |yi - yj|.
.
问 有多少种点的组合使得 两种两点的计算方式的结果相等 欧几里得距离等于曼哈顿距离
题解: 等式两边平方 整理移项之后可以发现 两点的x坐标相等或者y坐标相等情况下两种计算方式结果相等
用了 multiset+pair
其中最关键的处理是 当x y都对应相等情况下 去重处理
用的是pair
x相等的+y相等的-xy相等的
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#define ll __int64
using namespace std;
int n;
multiset<int>s1;
multiset<int>s2;
pair<int,int>gg;
multiset<pair<int,int > >ggg;
int a[],b[];
ll jishu=;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d %d",&a[i],&b[i]);
gg.first=a[i];
gg.second=b[i];
ggg.insert(gg);
s1.insert(a[i]);
s2.insert(b[i]);
}
for(int i=;i<=n;i++)
{
ll exm=s1.count (a[i]);
jishu=jishu+exm*(exm-)/;
s1.erase(a[i]);
}
for(int i=;i<=n;i++)
{
ll exm=s2.count(b[i]);
jishu=jishu+exm*(exm-)/;
s2.erase(b[i]);
}
//printf("%I64d\n",jishu);
for(int i=;i<=n;i++)
{
gg.first=a[i];
gg.second=b[i];
ll exm=ggg.count(gg);
jishu=jishu-exm*(exm-)/;
ggg.erase(gg);
}
printf("%I64d\n",jishu);
return ;
}
Codeforces Round #345 (Div. 2) C (multiset+pair )的更多相关文章
- Codeforces Round #249 (Div. 2)B(贪心法)
B. Pasha Maximizes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #250 (Div. 2)A(英语学习)
链接:http://codeforces.com/contest/437/problem/A A. The Child and Homework time limit per test 1 secon ...
- Codeforces Round #243 (Div. 2) B(思维模拟题)
http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...
- Codeforces Round #272 (Div. 1)D(字符串DP)
D. Dreamoon and Binary time limit per test 2 seconds memory limit per test 512 megabytes input stand ...
- Codeforces Round #554 (Div. 2)-C(gcd应用)
题目链接:https://codeforces.com/contest/1152/problem/C 题意:给定a,b(<1e9).求使得lcm(a+k,b+k)最小的k,若有多个k,求最小的k ...
- Codeforces Round #532 (Div. 2)- C(公式计算)
NN is an experienced internet user and that means he spends a lot of time on the social media. Once ...
- Codeforces Round #527 (Div. 3)F(DFS,DP)
#include<bits/stdc++.h>using namespace std;const int N=200005;int n,A[N];long long Mx,tot,S[N] ...
- Codeforces Round #618 (Div. 1)A(观察规律)
实际上函数值为x&(-y) 答案仅和第一个数字放谁有关 #define HAVE_STRUCT_TIMESPEC #include <bits/stdc++.h> using na ...
- Codeforces Round #272 (Div. 1)C(字符串DP)
C. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...
随机推荐
- 【wx:if】小程序条件渲染的使用说明
语法,以view为例: <view xw:if="{{条件}}">aaaa</view> <view xw:elif="{{条件}}&quo ...
- 人艰不拆之破解低版本IE不兼容mediaQuery
先放个链接 大家预览下 http://scottjehl.github.io/Respond/test/test.html 值得注意的是 将页面源代码下载到本地时,直接用IE打开是没有效果的.需要把静 ...
- java学习笔记-9.违例差错控制
1.违例规范是告诉程序员这个方法可能抛出哪些类型的异常.他的格式在方法声明中,位于自变量(参数)列表的后面,如void f() throws tooBig, tooSmall, divZero { ...
- HADOOP docker(四):安装hive
1.hive简介2.安装hive2.1 环境准备2.1.1 下载安装包2.1.2 设置hive用户的环境变量2.1.3 hive服务端配置文件2.1.4 hive客户端配置文件2.1.4 分发hive ...
- OpenCV学习5-----使用Mat合并多张图像
最近做实验需要对比实验结果,需要将几张图片拼在一起,直观对比. 尝试用OpenCV解决. 核心思想其实是 声明一个足够大的,正好容纳下那几张图片的mat,然后将拼图依次copy到大图片相应的位置. ...
- URAL 1297 Palindrome(Manacher)
The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent ...
- 【备忘】mysql常用操作汇总
1.增删改查 // 插入一条数据 insert into tableName values('liu','bei') // 删除一条数据 delete from tableName where las ...
- Thunder团队第六周 - Scrum会议5
Scrum会议5 小组名称:Thunder 项目名称:i阅app Scrum Master:翟宇豪 工作照片: 胡佑蓉同学在拍照,所以不在照片内. 参会成员: 王航:http://www.cnblog ...
- JAVA mysql数据库 配置
mysql 版本 5.7 数据库连接版本 <!--MySql--><dependency> <groupId>mysql</groupId> <a ...
- windows编程了解
文章:浅谈Windows API编程 (这个经典)