codeforce 621B Wet Shark and Bishops

对角线 x1+y1=x2+y2 或者x1-y1=x2-y2

 1 #include<iostream>
 2 #include<string>
 3 #include<algorithm>
 4 #include<cstdlib>
 5 #include<cstdio>
 6 #include<set>
 7 #include<map>
 8 #include<vector>
 9 #include<cstring>
10 #include<stack>
11 #include<cmath>
12 #include<queue>
13 #include <bits/stdc++.h>
14 using namespace std;
15 #define INF 0x3f3f3f3f
16 #define ll long long
17 #define clc(a,b) memset(a,b,sizeof(a))
18 const int maxn=4010;
19
20 int main()
21 {
22     int n;
23     int x,y;
24     int a[maxn];
25     int b[maxn];
26     scanf("%d",&n);
27     clc(a,0);
28     clc(b,0);
29     for(int i=0;i<n;i++)
30     {
31         scanf("%d%d",&x,&y);
32         a[x+y]++;
33         b[x-y+2000]++;
34     }
35     ll sum=0;
36     for(int i=0;i<=2000;i++)
37     {
38         if(a[i]%2)
39             sum+=(a[i]-1)/2*a[i];
40         else
41             sum+=a[i]/2*(a[i]-1);
42     }
43     for(int i=-999+2000;i<=999+2000;i++)
44     {
45         if(b[i]%2)
46             sum+=(b[i]-1)/2*b[i];
47         else
48             sum+=b[i]/2*(b[i]-1);
49     }
50     printf("%I64d\n",sum);
51     return 0;
52 }

时间: 2024-10-12 10:07:21

codeforce 621B Wet Shark and Bishops的相关文章

CodeForces 621B Wet Shark and Bishops

记录一下每个对角线上有几个,然后就可以算了 #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #include<vector> #include<algorithm> using namespace std; const int maxn=2000+10; int n; long long w1[maxn]; long long w2[maxn]; l

Wet Shark and Bishops(思维)

Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack e

【CodeForces 621B】Wet Shark and Bishops

题 题意 1000*1000的格子里,给你n≤200 000个点的坐标,求有多少对在一个对角线上. 分析 如果求每个点有几个共对角线的点,会超时. 考虑到对角线总共就主对角线1999条+副对角线1999条,我们可以求每个对角线有几对点. 同一条主对角线上的元素有a[i]个,就有C(a[i],2)对点: 同一条副对角线上的元素有b[i]个,就有C(b[i],2)对点. 读入x和y后, x+y相同的就在同一副对角线,x+y范围是(2,2000), x-y相同的就是同一主对角线,x-y范围是(-999

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&

【CodeForces 621A】Wet Shark and Odd and Even

题 Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the n 

【CodeForces 621C】Wet Shark and Flowers

题 There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i andi + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too. Each shark will grow some number of flowers si. For i

矩阵乘法&amp;&amp;dp加速矩阵的思路(E. Wet Shark and Blocks)

There are b blocks of digits. Each one consisting of the same n digits, which are given to you in the input. Wet Shark must choose exactly one digit from each block and concatenate all of those digits together to form one large integer. For example,

CodeForces 621A Wet Shark and Odd and Even

水题 #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #include<vector> #include<algorithm> using namespace std; int n; long long a[100000+10]; int main() { scanf("%d",&n); for(int i=0;i<

CodeForces 621C Wet Shark and Flowers

方法可以转化一下,先计算每一个鲨鱼在自己范围内的数能被所给素数整除的个数有几个,从而得到能被整除的概率,设为f1,不能被整除的概率设为f2. 然后计算每相邻两只鲨鱼能获得钱的期望概率,f=w[id1].f1*w[id2].f2+w[id1].f2*w[id2].f1+w[id1].f1*w[id2].f1; f*2000就是这两只鲨鱼能获得的期望金钱,然后枚举一下所有相邻的鲨鱼,累加即可. #include<cstdio> #include<cstring> #include<