思路:
直接统计所有的主对角线和负对角线上的点的个数,然后cn2就出来了!(x+y==b是负对角线上的点,x-y+1000是主对角线上的点!)
代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int n;
int a[2005];
int b[2005];
int main()
{
while(scanf("%d",&n)!=EOF)
{
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[x-y+1000]++;
}
__int64 sum=0;
for(int i=0;i<=2000;i++)
{
sum+=a[i]*(a[i]-1)/2;
sum+=b[i]*(b[i]-1)/2;
}
printf("%I64d\n",sum);
}
return 0;
}