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\n", ans);
    return 0;
}
时间: 2024-08-03 14:45:24

Codeforces Round #341 Div.2 B. Wet Shark and Bishops的相关文章

Codeforces Round #341 Div.2 C. Wet Shark and Flowers

题意: 不概括了..太长了.. 额第一次做这种问题 算是概率dp吗? 保存前缀项中第一个和最后一个的概率 然后每添加新的一项 就解除前缀和第一项和最后一项的关系 并添加新的一项和保存的两项的关系 这里关系指的是两者相邻会产生的额外收入(其中一个满足条件就能得到 因此公式是 2000 * (rate[a] * rate[b] + rate[a] * ( 1 - rate[b]) + rate[b] * (1 - rate[a])) 至于一开始为什么老是调不过去呢..我发现添加第三项的时候前两项是不

Codeforces Round #341 Div.2 A. Wet Shark and Odd and Even

题意是得到最大的偶数和 解决办法很简单 排个序 取和 如果是奇数就减去最小的奇数 #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <vector> #include <algorithm> #define INF 0x3f3f3f3f #define mem(str,x) memset(str,(x),sizeof(str)

Codeforces Round #341 (Div. 2) E. Wet Shark and Blocks(矩阵优化DP)

题目链接:点击打开链接 题意:给n个数作为一个块,有b个块,从其中若干个中选择数,每个块只能选一个数,最后组成一个数模x等于k的方法数. 思路:很容易想到这样一个DP方程 : 用dp[i][j]表示现在i位,余数是j.那么dp[i + 1][(j * 10 + k) % x] = dp[i][j] * cnt[k],k是指枚举放1~9中哪一位. 因为b特别大,显然要矩阵优化,知道了DP方程,其实矩阵的构造特别简单. 根据矩阵相乘的规则, 其实这个矩阵就是A[j][(j*10+a[k])%x]++

Codeforces Round #341 (Div. 2) C. Wet Shark and Flowers(简单容斥)

题目链接:点击打开链接 题意:有n个人围坐成一圈,每个人可以从a[i].l 到 a[i].r里选一个数,如果相邻两个数的乘积能整除p,那么就奖励他们一人1000,求所得钱的总和的期望. 思路:既然求期望, 先求概率. 显然是要求每组相邻两个人的值乘积能否被p整除, 可以很容易知道在区间里有多少个数不能被p整除, 正难则反, 就能算出相邻两个有多少种组合不能被p整除, 那么也就很容易算出每组可以被p整除的概率, 乘上2000就是每组的期望, 期望加和就是总的期望. 细节参见代码: #include

Codeforces Round #341 (Div. 2) E - Wet Shark and Blocks

题目大意:有m (m<=1e9) 个相同的块,每个块里边有n个数,每个数的范围是1-9,从每个块里边取出来一个数组成一个数,让你求组成的方案中 被x取模后,值为k的方案数.(1<=k<x<=100) 思路:刚开始把m看成了1e5,写了一发数位dp,果断RE,然后我在考虑从当块前状态转移到下一个块状态模数的改变都用的是一套规则,因为 每个块里面的数字都是一样的,那么我们就可以很开心地构造出一个x*x的矩阵进行快速幂啦. #include<bits/stdc++.h> #d

Codeforces Round #341 (Div. 2) ABCDE

http://www.cnblogs.com/wenruo/p/5176375.html A. Wet Shark and Odd and Even 题意:输入n个数,选择其中任意个数,使和最大且为奇数. 题解:算出所有数的和,如果奇数的个数为奇数个,则减去最小的奇数,否则不用处理. #include <bits/stdc++.h> using namespace std; #define PI acos(-1.0) #define EXP exp(1.0) #define ESP 1E-6

Codeforces Round #341 (Div. 2)

在家都变的懒惰了,好久没写题解了,补补CF 模拟 A - Wet Shark and Odd and Even #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 + 5; const int INF = 0x3f3f3f3f; int main(void) { std::vector<int> vec; int n; scanf ("%d", &n); ll sum = 0;

Codeforces Codeforces Round #484 (Div. 2) D. Shark

Codeforces Codeforces Round #484 (Div. 2) D. Shark 题目连接: http://codeforces.com/contest/982/problem/D Description For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/