hihocode——#1497 : Queen Attack

http://hihocoder.com/problemset/problem/1497
时间限制: 10000ms
单点时限: 1000ms
内存限制: 256MB

描述

There are N queens in an infinite chessboard. We say two queens may attack each other if they are in the same vertical line, horizontal line or diagonal line even if there are other queens sitting between them.

Now given the positions of the queens, find out how many pairs may attack each other?

输入

The first line contains an integer N.

Then N lines follow. Each line contains 2 integers Ri and Ci indicating there is a queen in the Ri-th row and Ci-th column.  

No two queens share the same position.  

For 80% of the data, 1 <= N <= 1000

For 100% of the data, 1 <= N <= 100000, 0 <= Ri, Ci <= 1000000000

输出

One integer, the number of pairs may attack each other.

样例输入
5  
1 1  
2 2  
3 3   
1 3
3 1

样例输出

10


题意:给你很多皇后的坐标,问有多少对会互相攻击~~

思路:只要用4个map记录行列和两个斜边出现的次数就行~~


#include
using namespace std;

map m1;
map m2;
map m3;
map m4;
typedef long long LL;
int main()
{
    int n;
    LL ans=0;
    scanf("%d",&n);
    for(int i=0; i


10

你可能感兴趣的:(acm)