• # Codeforces Round #345 (Div. 2) C （multiset+pair ）

C. Watchmen
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
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.

Input

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.

Output

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.

Examples
input
`31 17 51 5`
output
`2`
input
`60 00 10 2-1 10 11 1`
output
`11`
Note

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相等的

``` 1 #include<bits/stdc++.h>
2 #include<iostream>
3 #include<cstdio>
4 #define ll __int64
5 using namespace std;
6 int n;
7 multiset<int>s1;
8 multiset<int>s2;
9 pair<int,int>gg;
10 multiset<pair<int,int > >ggg;
11 int a[200005],b[200005];
12 ll jishu=0;
13 int main()
14 {
15     scanf("%d",&n);
16     for(int i=1;i<=n;i++)
17         {
18             scanf("%d %d",&a[i],&b[i]);
19             gg.first=a[i];
20             gg.second=b[i];
21             ggg.insert(gg);
22             s1.insert(a[i]);
23             s2.insert(b[i]);
24         }
25     for(int i=1;i<=n;i++)
26     {
27        ll exm=s1.count (a[i]);
28        jishu=jishu+exm*(exm-1)/2;
29        s1.erase(a[i]);
30     }
31      for(int i=1;i<=n;i++)
32     {
33         ll exm=s2.count(b[i]);
34        jishu=jishu+exm*(exm-1)/2;
35         s2.erase(b[i]);
36     }
37     //printf("%I64d
",jishu);
38     for(int i=1;i<=n;i++)
39     {
40         gg.first=a[i];
41         gg.second=b[i];
42         ll exm=ggg.count(gg);
43             jishu=jishu-exm*(exm-1)/2;
44         ggg.erase(gg);
45     }
46     printf("%I64d
",jishu);
47     return 0;
48 }```
View Code
• 相关阅读:
权当这是开始吧
rabbitmq实现一台服务器同时给指定部分的consumer发送消息（tp框架）（第六篇）
部分替换mysql表中某列的字段
rabbitmq实现一台服务器同时给指定部分的consumer发送消息（tp框架）（第五篇）
rabbitmq实现一台服务器同时给所有的consumer发送消息（tp框架）（第四篇）
rabbit服务器挂掉以后，保证队列消息还存在（tp框架）（第三篇）
HDU 1114 Piggy-Bank (poj1384)
01背包
等价表达式(noip2005)
机器翻译（noip2010）
• 原文地址：https://www.cnblogs.com/hsd-/p/5255188.html