CodeForces 650A Watchmen
Posted Fighting Heart
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces 650A Watchmen相关的知识,希望对你有一定的参考价值。
两种距离相等,必然是在一条竖直线上或者一条水平线上。重复的再减一下即可。
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <cmath> #include <algorithm> #include <ctime> #include <stack> using namespace std; typedef long long LL; const int maxn=2e5+9; const int inf=1e9+9; struct II { LL x,y; }num[maxn]; int cmp1(II a,II b); int cmp2(II a,II b); int cmp3(II a,II b); int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%I64d%I64d",&num[i].x,&num[i].y); } sort(num+1,num+1+n,cmp1); LL ans=0; LL tmp=1; for(int i=2;i<=n;i++) { if(num[i].x==num[i-1].x) tmp++; else { ans+=tmp*(tmp-1)/2; tmp=1; } } ans+=tmp*(tmp-1)/2; sort(num+1,num+1+n,cmp2); tmp=1; for(int i=2;i<=n;i++) { if(num[i].y==num[i-1].y) tmp++; else { ans+=tmp*(tmp-1)/2; tmp=1; } } ans+=tmp*(tmp-1)/2; sort(num+1,num+1+n,cmp3); LL nn=1; for(int i=2;i<=n;i++) { if(num[i].x==num[i-1].x && num[i].y==num[i-1].y) nn++; else { ans-=(nn)*(nn-1)/2; nn=1; } } ans-=(nn)*(nn-1)/2; printf("%I64d\n",ans); return 0; } int cmp3(II a,II b) { if(a.x==b.x) return a.y<b.y; return a.x<b.x; } int cmp2(II a,II b) { return a.y<b.y; } int cmp1(II a,II b) { return a.x<b.x; }
以上是关于CodeForces 650A Watchmen的主要内容,如果未能解决你的问题,请参考以下文章
codeforces Codeforces 650A Watchmen
[2016-03-08][codeforces][651][C][Watchmen]
CodeForces - 651C Watchmen(map)
Codeforces Round #345 (Div. 2)C. Watchmen(想法题)
Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 树状数组维护区间最大值(示(代