zoukankan      html  css  js  c++  java
  • 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
    ",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;
    }
  • 相关阅读:
    OO第三单元博客作业
    OO第二单元博客作业
    OO第一单元博客作业
    OO第四单元总结
    OO第三次作业总结
    OO第二单元作业总结
    OO第一单元作业总结
    面向对象总结博客
    面向对象第三单元总结博客
    面向对象第二单元总结博客
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5252713.html
Copyright © 2011-2022 走看看