您的位置:首页 > 大数据 > 人工智能

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

2016-03-08 18:58 387 查看
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

#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[200005],b[200005];
ll jishu=0;
int main()
{
scanf("%d",&n);
for(int i=1;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=1;i<=n;i++)
{
ll exm=s1.count (a[i]);
jishu=jishu+exm*(exm-1)/2;
s1.erase(a[i]);
}
for(int i=1;i<=n;i++)
{
ll exm=s2.count(b[i]);
jishu=jishu+exm*(exm-1)/2;
s2.erase(b[i]);
}
//printf("%I64d\n",jishu);
for(int i=1;i<=n;i++)
{
gg.first=a[i];
gg.second=b[i];
ll exm=ggg.count(gg);
jishu=jishu-exm*(exm-1)/2;
ggg.erase(gg);
}
printf("%I64d\n",jishu);
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: