zoukankan      html  css  js  c++  java
  • Codeforces Round #341 Div.2 B. Wet Shark and Bishops

    题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数

    由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y

    然后每个数组中扫描重复数字k ans加上kC2就行了

    wa了两发的原因是没考虑到如果整个数组都是重复的 那要最后额外加一次

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <queue>
    #include <vector>
    #include <algorithm>
    #define INF 0x3f3f3f3f
    #define mem(str,x) memset(str,(x),sizeof(str))  
    #define STOP puts("Pause");
    using namespace std;
    typedef long long LL;
    
    int n, node[200010], node2[200010];
    LL ans;
    
    int main()
    {
        ans = 0;
        scanf("%d", &n);
        for(int i = 1; i <= n; i++){
            int x, y;
            scanf("%d%d", &x, &y);
            node[i] = x - y;
            node2[i] = x + y;
        }
        sort(node + 1, node + 1 + n);
        sort(node2 + 1, node2 + 1 + n);
        LL count = 1;
        for(int i = 2; i <= n; i++){
            if(node[i] == node[i-1]) count++;
            else{
                ans += (count * (count - 1) / 2);
                count = 1;
            }
        }
        ans += (count * (count - 1) / 2);
        count = 1;
        for(int i = 2; i <= n; i++){
            if(node2[i] == node2[i-1]) count++;
            else{
                ans += (count * (count - 1) / 2);
                count = 1;
            }
        }
        ans += (count * (count - 1) / 2);
        printf("%I64d
    ", ans);
        return 0;
    }
  • 相关阅读:
    Codeforces 1316B String Modification
    Codeforces 1305C Kuroni and Impossible Calculation
    Codeforces 1305B Kuroni and Simple Strings
    Codeforces 1321D Navigation System
    Codeforces 1321C Remove Adjacent
    Codeforces 1321B Journey Planning
    Operating systems Chapter 6
    Operating systems Chapter 5
    Abandoned country HDU
    Computer HDU
  • 原文地址:https://www.cnblogs.com/quasar/p/5174236.html
Copyright © 2011-2022 走看看