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;
    }
  • 相关阅读:
    微信支付遇到的坑
    linux搭载discuz
    关于php自带的访问服务器xml的方法的坑
    yii的验证码
    菜鸟配置阿里云
    ajax(通过jQuery实现)
    leetcode95 Unique Binary Search Trees II
    leetcode96 Unique Binary Search Trees
    leetcode98 Validate Binary Search Tree
    leetcode-99 Recover_Binary_Search_Tree
  • 原文地址:https://www.cnblogs.com/quasar/p/5174236.html
Copyright © 2011-2022 走看看