Time Limit: 2000MS |
| Memory Limit: 262144KB |
| 64bit IO Format: %I64d & %I64u |
Description 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. Input 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 Output one integer — the number of pairs of bishops which attack each other. Sample Input Input 51 11 53 35 15 5 Output 6 Input 31 12 33 5 Output 0 Hint 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) //题意:输入n,在输入n个点的坐标 表示在1000*1000的矩阵中有n条鲨鱼,它们所在的坐标即为所给的。如果在矩阵的对角线上有多条鲨鱼,那么这条对角线上的多条鲨鱼就会打架(并且即使它们不相邻,他们也会打架),问总共有多少对打架的鲨鱼。 //思路: 因为它是一个1000*1000的正方形,所以它的对角线条数总共有4000条,分别是y=x+b的两千条和y=-x+b的两千条.因为它们分别都是平行的,所以它们的b(截距)是唯一的。在输入的时候分别对它们的截距b的值进行记录累加就行了。 求出对应截距的个数后,就可以计算每条对角线上的打架鲨鱼的对数了。
|