B. Wet Shark and Bishops
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 test(s)
Input
5
1 1
1 5
3 3
5 1
5 5
Output
6
Input
3
1 1
2 3
3 5
Output
0
Note

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) do not attack each other because they do not share the same diagonal.

题意:棋盘上象可以互相攻击(象只能在斜率为1 -1上攻击)

输入n个象 判断有多少种攻击配对

题解: 斜率为1的 x-y的值相同

斜率为-1的x+y的值相同   (都在同一对角线上)

数组标记 或map标记

每条线上的配对数量 fun()实现

#include<bits/stdc++.h>
using namespace std;
#define ll __int64
int flag[4005];
int flag1[4005];
ll fun(ll n,ll m)
{
ll sum=1;
for(ll i=1,j=n;i<=m;i++,j--)
sum=sum*j/i;
return sum;
}
int main()
{
ll x,y,z,i;
scanf("%I64d",&x);
for(i=0;i<x;i++)
{
scanf("%I64d%I64d",&y,&z);
flag[y+z]++;
flag1[y-z+1000]++;
}
ll ans=0;
for(i=0;i<=3000;i++)
{
if(flag[i])
ans+=fun(flag[i],2);
if(flag1[i])
ans+=fun(flag1[i],2);
}
printf("%I64d\n",ans);
return 0;
}

  

Codeforces Round #341 (Div. 2)B的更多相关文章

  1. Codeforces Round #341 (Div. 2) E. Wet Shark and Blocks dp+矩阵加速

    题目链接: http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test2 se ...

  2. Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese 数学

    D. Rat Kwesh and Cheese 题目连接: http://www.codeforces.com/contest/621/problem/D Description Wet Shark ...

  3. Codeforces Round #341 Div.2 D. Rat Kwesh and Cheese

    嗯本来想着直接算出来不就行了吗 然后我想到了200^200^200....... 好吧其实也不难取两次log就行了 然后我第一次写出来log就写残了........... log里面的拆分要仔细啊.. ...

  4. Codeforces Round #341 Div.2 C. Wet Shark and Flowers

    题意: 不概括了..太长了.. 额第一次做这种问题 算是概率dp吗? 保存前缀项中第一个和最后一个的概率 然后每添加新的一项 就解除前缀和第一项和最后一项的关系 并添加新的一项和保存的两项的关系 这里 ...

  5. Codeforces Round #341 Div.2 B. Wet Shark and Bishops

    题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数 由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y 然后每个数组中扫描重复数字k ans加上kC ...

  6. Codeforces Round #341 (Div. 2)

    在家都变的懒惰了,好久没写题解了,补补CF 模拟 A - Wet Shark and Odd and Even #include <bits/stdc++.h> typedef long ...

  7. Codeforces Round #341 Div.2 A. Wet Shark and Odd and Even

    题意是得到最大的偶数和 解决办法很简单 排个序 取和 如果是奇数就减去最小的奇数 #include <cstdio> #include <cmath> #include < ...

  8. Codeforces Round #341 (Div. 2) ABCDE

    http://www.cnblogs.com/wenruo/p/5176375.html A. Wet Shark and Odd and Even 题意:输入n个数,选择其中任意个数,使和最大且为奇 ...

  9. Codeforces Round #341 (Div. 2) E - Wet Shark and Blocks

    题目大意:有m (m<=1e9) 个相同的块,每个块里边有n个数,每个数的范围是1-9,从每个块里边取出来一个数组成一个数,让你求组成的方案中 被x取模后,值为k的方案数.(1<=k< ...

  10. Codeforces Round #341 (Div. 2) C. Mike and Chocolate Thieves 二分

    C. Mike and Chocolate Thieves time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. 给大家推荐:五个Python小项目,Github上的人气很高的

    1.深度学习框架 Pytorch https://github.com/pytorch/pytorch PyTorch 是一个 Torch7 团队开源的 Python 优先的深度学习框架,提供两个高级 ...

  2. python 终极篇 cookie与session

    ()cookie与session---------->>>>>>>>>>>>>>>>>>&g ...

  3. Spark mlib的本地向量

    Spark mlib的本地向量有两种: DenseVctor :稠密向量 其创建方式 Vector.dense(数据) SparseVector :稀疏向量 其创建方式有两种: 方法一:Vector. ...

  4. appcrawler遍历工具常用方法

    Usage: appcrawler [options] -a, --app <value> Android或者iOS的文件地址, 可以是网络地址, 赋值给appium的app选项 -c,  ...

  5. 在 Ubuntu 下安装 Deepin 的 QQ、微信、百度云和迅雷等软件

    在以前的文章 Ubuntu 常用软件推荐(QQ.微信.MATLAB等)及安装过程 中,我们用 Wine QQ 和 Electronic Wechat 来解决 Ubuntu 系统下使用 QQ 和微信的难 ...

  6. LeetCode 104——二叉树中的最大深度

    1. 题目 2. 解答 如果根节点为空,直接返回 0.如果根节点非空,递归得到其左右子树的深度,树的深度就为左右子树深度的最大值加 1. /** * Definition for a binary t ...

  7. 微软的XML可视化编辑器:XML Notepad 2007

    最近项目需要定义xml协议格式,编写xml文件比较多,之前使用xml spy工具,但是不够轻量级. 微软提供的xml nodepad 2007很实用,希望能给大家提供帮助. 运行后的界面 下载地址:h ...

  8. fragment的介绍与使用

    稍稍摘录一段Fragment.java中的说明文档. /** * A Fragment is a piece of an application's user interface or behavio ...

  9. iOS- 无处不在,详解iOS集成第三方登录(SSO授权登录<无需密码>)

    1.前言   不多说,第三登录无处不在!必备技能,今天以新浪微博为例. 这是上次写的iOS第三方社交分享:http://www.cnblogs.com/qingche/p/3727559.html 可 ...

  10. TCP系列03—连接管理—2、TCP连接的同时打开和同时关闭

    在前面的内容中我们介绍了TCP连接管理中最常见的三次握手方式和四次挥手的方式.但是有可能A和B两端同时执行主动打开并连接对方或者同时执行主动关闭连接(尽管发生这种情况的可能性比较低低),这个时候的流程 ...