*Wet Shark and Bishops(思维) CodeForces
来源:互联网 发布:mysql pid文件丢失 编辑:程序博客网 时间:2024/05/16 08:13
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<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[2005];int b[2005];int main(){int t;memset(a,0,sizeof(a));memset(b,0,sizeof(b));cin >> t;int s,q;for(int i=0; i<t; i++){cin >> s >> q;a[s-q+1001]++;b[s+q]++;}int add=0;for(int i=2; i<=2000; i++){add+=a[i]*(a[i]-1)/2+b[i]*(b[i]-1)/2;}cout << add << endl;return 0;}
- *Wet Shark and Bishops(思维) CodeForces
- 【CodeForces】#621B - Wet Shark and Bishops(思维)
- Wet Shark and Bishops(思维)
- (思维)Wet Shark and Bishops
- Codeforces 621B - Wet Shark and Bishops(思维)
- CodeForces 621 B. Wet Shark and Bishops(水~)
- Codeforces--621B--Wet Shark and Bishops(数学)
- CodeForces 621 B Wet Shark and Bishops
- 【codeforces】#621B-Wet Shark and Bishops
- 【CodeForces】[621B]Wet Shark and Bishops
- 【CodeForces】#621B - Wet Shark and Bishops
- CodeForces 621B Wet Shark and Bishops
- CodeForces 621B Wet Shark and Bishops
- Codeforces 621B Wet Shark and Bishops
- Wet Shark and Bishops
- Wet Shark and Bishops
- Wet Shark and Bishops
- codeforces621B. Wet Shark and Bishops
- E
- Java EE编程技术学习笔记(2)-Servlet
- J
- 【设计模式】 装饰模式与代理模式的对比
- Rosalind-翻译RNA序列
- *Wet Shark and Bishops(思维) CodeForces
- DTMF信号检测之goertzel算法
- Android中的一些小知识点
- Java EE编程技术学习笔记(3)-JSP
- C#知识积累
- LBG矢量量化算法
- 数组——找最大值
- d3 绘制中国地图城市及城市间的连线
- 【代码片-1】 Project Perfect让Swift在服务器端跑起来-引言(一)