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 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.
Example
5
1 1
1 5
3 3
5 1
5 5
6
3
1 1
2 3
3 5
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 or x-y相等,这里需要注意的是x-y可能会出现负数,所以这里用x-y+3000来代替x-y
AC代码
#include<stdio.h>
#include<string.h> int main()
{
int n;
int x, y;
int attack[];
int sum;
while(~scanf("%d", &n))
{
sum = ;
memset(attack, , sizeof(attack));
for(int i = ; i < n; i++)
{
scanf("%d %d", &x, &y);
attack[x+y]++;
attack[x-y+]++;
}
for(int i = ; i < ; i++)
{
if(attack[i] > )
sum += attack[i]*(attack[i]-)/;
}
printf("%d\n", sum);
} return ;
}
Wet Shark and Bishops(思维)的更多相关文章
- B. Wet Shark and Bishops(思维)
B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces 612B. Wet Shark and Bishops 模拟
B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...
- Codeforces Round #341 Div.2 B. Wet Shark and Bishops
题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数 由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y 然后每个数组中扫描重复数字k ans加上kC ...
- 【CodeForces 621B】Wet Shark and Bishops
题 题意 1000*1000的格子里,给你n≤200 000个点的坐标,求有多少对在一个对角线上. 分析 如果求每个点有几个共对角线的点,会超时. 考虑到对角线总共就主对角线1999条+副对角线199 ...
- codeforce 621B Wet Shark and Bishops
对角线 x1+y1=x2+y2 或者x1-y1=x2-y2 #include<iostream> #include<string> #include<algorithm& ...
- Chocolate&&木块拼接&&Cards&& Wet Shark and Bishops
B. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- CodeForces 621B Wet Shark and Bishops
记录一下每个对角线上有几个,然后就可以算了 #include<cstdio> #include<cstring> #include<cmath> #include& ...
- Codeforces--621B--Wet Shark and Bishops(数学)
B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Wet Shark and Flowers(思维)
C. Wet Shark and Flowers time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- 接口方式[推荐]/动态SQL语句
MVC目录结构: Src -- com.shxt.servlet[控制层] --com.shxt.service[业务逻辑层] --com.shxt.model[实体Bean,用来承载数据] --co ...
- POJ3321(dfs序列+树状数组)
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25711 Accepted: 7624 Descr ...
- Spring Boot Starter 速查
Spring Boot应用启动器基本的一共有40多种,常用的如下 1)spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. 2)spring ...
- 摘之知乎网友...PHYTIN学习
作者:东瓜王链接:https://www.zhihu.com/question/19593179/answer/23746083来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
- [译] SystemTap
SystemTap 什么是system Tap ? SystemTap 提供环境用来获得更多关于内核几乎所有组件的信息,用以被进一步分析.SystemTap也可以被当作一种工具,为用户研究和监控内核详 ...
- linux 学习2 常用命令
1.显示日期的指令: date 2. [Tab]按键---具有『命令补全』不『档案补齐』的功能 3: su和 sudo su用于用户之间的切换. su在不加任何参数,默认为切换到root用户 ...
- KVO键值监听
KVO 键值监听:当我想知道一个对象的属性是否发生改变的时候 做出响应,就需要添加监听keypath 和 key的区别keypath会自动寻找子类的属性key只会寻找当前类的属性添加键值监听[pers ...
- shell脚本 回顾 小练习
1.把/OPT目录下(包含子目录)下所有后缀为“.sh”的文件后缀变更为“.shell” 2.将A.B.C目录下的文件A1.A2.A3文件改名为A4.A5.A63.如何在vi模式下将文件中的aa字符串 ...
- [Chapter 3 Process]Practice 3.2 Including the initial parent process, how many processes are created by the program shown in Figure?
3.2 Including the initial parent process, how many processes are created by the program shown in Fig ...
- 新建 FrameMaker API 时引用目录的设置
如果将FDK安装目录下的Sample项目拷贝到其它目录编译,往往会报错 c1083 找不到fapi.h等头文件,或者Link时报错找不到.lib文件. 1.可通过菜单-项目-xxx属性-配置属性-c/ ...