2017暑期集训——Wet Shark and Bishops(思维)
来源:互联网 发布:js做99乘法表 编辑:程序博客网 时间:2024/06/13 03:03
J - *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 each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other.
The first line of the input contains n (1 ≤ n ≤ 200 000) — the number of bishops.
Each of next n lines contains two space separated integers xi and yi (1 ≤ xi, yi ≤ 1000) — the number of row and the number of column where i-th bishop is positioned. It's guaranteed that no two bishops share the same position.
Output one integer — the number of pairs of bishops which attack each other.
51 11 53 35 15 5
6
31 12 33 5
0
In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.
#include<cstdio>#include<cstring>#define MAX 2000+22int main(){int n;long long a[MAX],b[MAX];while(~scanf("%d",&n)){memset(a,0,sizeof(a));memset(b,0,sizeof(b)); for(int i=0;i<n;i++){int x,y;scanf("%d%d",&x,&y);a[x+y]++;b[y-x+1000]++; }long long sum=0;for(int i=0;i<=2000;i++){if(a[i])sum+=(a[i]*(a[i]-1))/2;if(b[i])sum+=(b[i]*(b[i]-1))/2;}printf("%lld\n",sum);}return 0;}
- 2017暑期集训——Wet Shark and Bishops(思维)
- Wet Shark and Bishops(思维)
- *Wet Shark and Bishops(思维) CodeForces
- (思维)Wet Shark and Bishops
- 【CodeForces】#621B - Wet Shark and Bishops(思维)
- Wet Shark and Bishops
- Wet Shark and Bishops
- Wet Shark and Bishops
- Codeforces 621B - Wet Shark and Bishops(思维)
- codeforces621B. Wet Shark and Bishops
- CF621B - Wet Shark and Bishops
- B. Wet Shark and Bishops
- CodeForces 621 B. Wet Shark and Bishops(水~)
- Codeforces--621B--Wet Shark and Bishops(数学)
- codeforce 621B Wet Shark and Bishops
- codeforce 621 B. Wet Shark and Bishops
- CodeForces 621 B Wet Shark and Bishops
- 【codeforces】#621B-Wet Shark and Bishops
- 系统日志,配置IP
- YAML 语法
- 【KMP求字符串第一个匹配位置】hdu 1711
- LinkedHashMap和HashMap的比较使用
- VirtualBox下CentOS 7+ssh+samba
- 2017暑期集训——Wet Shark and Bishops(思维)
- HDU 2044 一只小蜜蜂...(DP递推)
- 几个经典递归问题用js实现
- 远程启动VMware并连接虚拟机
- Linux/Android系统知识之Linux入门篇--学习使用命令行
- Altium Designer 集成库的创建
- JMS--队列模式代码实现 (二)
- 八皇后问题(回溯法)
- poj1459 Power Network题解