对角线 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