码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 650A Watchmen

时间:2016-03-08 09:24:11      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

两种距离相等,必然是在一条竖直线上或者一条水平线上。重复的再减一下即可。

#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

标签:

原文地址:http://www.cnblogs.com/zufezzt/p/5252713.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!