CF#341-B-Wet Shark and Bishops-水题

http://codeforces.com/contest/621/problem/B


给你一个1000*1000的矩阵,上的n个点,

计算每个对角线上有多少个点,如果一个对角线有n个点,代表有n个牧师,会互相打架,计算打架总数


直接统计每条对角线多少个点,然后 ....n个人,有n*(n-1)/2场架,GG

//注意主对角线要+n,否则下标为负数


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include<stack>
using namespace std; 
__int64 L[2005*2];//副对角线元素之和 
__int64 R[2005*2]; //主对角线元素之和  
 
int main()
{ 
	int n;
	int i,x,y;
	scanf("%d",&n); 

	for (i=1;i<=n;i++)
	{
	 scanf("%d %d",&x,&y);
			  L[x+y]++;
			  R[x-y+1000]++;  //注意
	}
	__int64 sum=0;
	for (i=0;i<=2000;i++)
	{
		if (L[i]) sum+= L[i]*(L[i]-1)/2;
		if (R[i]) sum+= R[i]*(R[i]-1)/2;
	}
	printf("%I64d\n",sum);
	
	return 0;
} 


你可能感兴趣的:(CF#341-B-Wet Shark and Bishops-水题)