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 to1000. 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.

题解:

在同一斜线上的象可以相互攻击,问可以攻击的对数;由于x+y相等的象在同一/上,相减相等的在同一\上,计算相等的数目,对数就是n*(n-1)/2;

由于相减可能为负,加一个整数就可以了;

代码:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%I64d",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%I64d",x)
#define P_ printf(" ")
typedef __int64 LL;
const int MAXN=4040;
int m[MAXN];
int main(){
int n;
while(~SI(n)){
mem(m,0);
int a,b;
for(int i=0;i<n;i++){
SI(a);SI(b);
m[a+b]++;
m[a-b+3020]++;
}
LL ans=0;
for(int i=0;i<MAXN;i++){
if(m[i]){
// printf("%d %d\n",i,m[i]);
ans+=(m[i]-1)*m[i]/2;
}
}
printf("%I64d\n",ans);
}
return 0;
}

  

B. Wet Shark and Bishops(思维)的更多相关文章

  1. Codeforces 612B. Wet Shark and Bishops 模拟

    B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  2. Wet Shark and Bishops(思维)

    Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are nu ...

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

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

  4. 【CodeForces 621B】Wet Shark and Bishops

    题 题意 1000*1000的格子里,给你n≤200 000个点的坐标,求有多少对在一个对角线上. 分析 如果求每个点有几个共对角线的点,会超时. 考虑到对角线总共就主对角线1999条+副对角线199 ...

  5. codeforce 621B Wet Shark and Bishops

    对角线 x1+y1=x2+y2 或者x1-y1=x2-y2 #include<iostream> #include<string> #include<algorithm& ...

  6. Chocolate&&木块拼接&&Cards&& Wet Shark and Bishops

    B. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  7. CodeForces 621B Wet Shark and Bishops

    记录一下每个对角线上有几个,然后就可以算了 #include<cstdio> #include<cstring> #include<cmath> #include& ...

  8. Codeforces--621B--Wet Shark and Bishops(数学)

     B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input ...

  9. Wet Shark and Flowers(思维)

    C. Wet Shark and Flowers time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. jchat:linux聊天程序1:简介

    做一个linux的聊天软件,虽然没什么创意,但是它可以用来锻炼和测试我对网络编程的掌握程度,也借此机会做一些有意思的程序. 这里做的是linux下一个命令行的客户端与服务器的聊天程序,没写界面,因为对 ...

  2. 写给初学者css优先级问题

    首先需要搞清楚几个基本概念 1.内嵌样式: 写在元素标签内的例如:<div style="background-color:red"> </div> 2.内 ...

  3. python----脚本文件的头部写法。

    #!/usr/bin/python #这里主要是为了指明python脚本解释器的路径. #!coding:utf-8#这个是为了告知python脚本文件解释器,此脚本的字符集. import sys ...

  4. 旧的VirtualBox News(从1.3.4开始)

    https://linuxtoy.org/archives.html https://linuxtoy.org/archives/virtualbox-134.html http://www.cnbl ...

  5. Qt 中程序自动重启

    参照至 dbzhang老师的博文,记录于此....... 要想理解重启,先得看看Qt程序怎么退出! 1.退出 int main(int argc, char** argv) { QApplicatio ...

  6. [开源]在iOS上实现Android风格的控件Toast

    [开源]在iOS上实现Android风格的控件Toast iOS的风格和Apple其他产品一样,简单而粗暴.没有给人其他选择的余地,让你又爱又恨.同样的,Apple对待iOS平台的开发人员和对待大众消 ...

  7. uva 10163 - Storage Keepers(01背包)

    题目链接:10163 - Storage Keepers 题目大意:给出m为仓库的数量, 给出n为有守夜人的数量, 然后给出n个数值,为对应守夜人应付的酬劳,每个守夜人的能力与他需要的酬劳是相等的,并 ...

  8. 自动备份多个MOSS站点集的脚本

    自动备份多个站点集的脚本(backupscript.bat)可以生成文件名如"Site80_20140327.bak"的备份文件. @echo offecho ++++++++++ ...

  9. CRM setValue方法日期类型字段赋值

    setvalue datetime 赋值 得到“/Date(14000023232323)/”  这样的值 需要把 /去掉 var dd = Result.yt_purchase_date.subst ...

  10. C/C++输入输出

    一. cin>>当碰到空格或换行符'\n'时,输入结束 该操作符是根据后面变量的类型读取数据. 输入结束条件 :遇到Enter.Space.Tab键. 对结束符的处理 :丢弃缓冲区中使得输 ...