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 ...
随机推荐
- leetcode-峰值检测
寻找峰值 峰值元素是指其值大于左右相邻值的元素. 给定一个输入数组 nums,其中 nums[i] ≠ nums[i+1],找到峰值元素并返回其索引. 数组可能包含多个峰值,在这种情况下,返回 ...
- Ubuntu16.04安装wps办公软件解决文字缺失
先到wps官网下载linux版wps安装包 选择64位的alpha版本下载: 下载完后,同样是cd到Downloads目录,用dpkg命令来安装它: cd Downloads/ sudo dpkg ...
- 【转载】Android 内存溢出如何发生的。
[转载]Android 内存溢出如何发生的. 且谈Android内存溢出 前言 关于android的内存溢出在创新文档库中也有不少,网络上也有很多这方面的资料.所以这遍文章不算是正真意义上的创新,仅仅 ...
- Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app.MRAppMaster
自己搭建了一套伪分布的大数据环境,运行Hadoop包中自带的示例时,出现如下错误: 错误: 找不到或无法加载主类 org.apache.hadoop.mapreduce.v2.app.MRAppMas ...
- 《剑指Offer》题三十一~题四十
三十一.栈的压入.弹出序列 题目:输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的数字均不相等.例如,序列{1, 2, 3, 4 ,5}是某栈的压栈序列 ...
- Pipeline组Alpha版本发布说明
Pipeline组Alpha版本发布说明 项目名称 Pipeline 项目版本 Alpha版本 负责人 北京航空航天大学计算机学院 ILoveSE 联系方式 http://www.cnblogs.co ...
- c++远征
---恢复内容开始--- 这两天初步接触了C++,抱着一种对这两个加号的理解的心态走进这门语言的学习. 1.mooc--慕课网c++课程链接:http://www.imooc.com/learn/34 ...
- python 抓取网上OJ试题
学校工作需要,需架设一台内网OJ服务器,采用了开源的hustoj.试题下载了hustoj的freeprblem的xml文件.导入时出现很多错误,不知什么原因.另外要将历年noip复赛试题加上去,但苦于 ...
- Java常用类之String
String 类: 1. java.lang.String 类代表不可变的字符序列: 2. “XXX” 为该类的一个对象: 3. String 类的常用构造方法: ① String(String o ...
- iOS开发解决页面滑动返回跟scrollView左右划冲突
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithG ...