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
View Code
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
相关文章推荐
- freeswitch You must define a domain called * in your directory
- NSURLErrorDomain Code=-999
- PAT1003-Highest Price in Supply Chain
- Codeforces #345 Div2 B Beautiful Paintings 构造/结论
- HDU 5293 Tree chain problem [树链剖分+线段树+树形DP]
- codeforces 651B Beautiful Paintings (想法)
- codeforces 651B Beautiful Paintings【优先队列】
- 浅析AIDL的使用
- 开发错误记录2 .MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
- Send an email using Telnet
- HDU 4819 Mosaic(二维线段树)
- uva 10090 So you want to be a 2n-aire?
- main
- RTAI安装与配置
- codeforces 651B Beautiful Paintings
- Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
- Codeforces--630A--Again Twenty Five! (水题)
- Codeforces--630A--Again Twenty Five! (水题)
- CodeForces 362B Petya and Staircases
- HDOJ 1848 Fibonacci again and again