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;
    }
  • 相关阅读:
    交叉熵损失函数
    均方根误差(RMSE),平均绝对误差(MAE),标准差(Standard Deviation)
    【转载】【矩阵,数组,列表之间相互转化】
    【数据集介绍】【Point04】
    【视频处理知识】
    【IOU】
    【模型训练】
    【图片操作】
    python 写 XML 文件
    【数组操作】 创建、排序
  • 原文地址:https://www.cnblogs.com/quasar/p/5174236.html
Copyright © 2011-2022 走看看