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 ...
随机推荐
- laravel config文件的使用
好多东西 由于许多地方都要使用与将来可能发生更改 我们需要把它提取出来 作为配置文件来使用 这样将来要修改的时候 只需要修改一处即可 学习源头: https://blog.csdn.net/linyu ...
- 第十课 go语言函数
1 内置函数 len() 函数可以接受不同类型参数并返回该类型的长度. 如果我们传入的是字符串则返回字符串的长度, 如果传入的是数组,则返回数组中包含的元素个数. 2 自定义函数 // 函数返回单个 ...
- 2015.12.24(圣诞节) 解决Oralce数据库将具有相同属性的多行合并为一行的简单方法多年想要wmsys.wm_concat
用到Oralce10g以后增加的函数wmsys.wm_concat 例如这张表的有两个字段,要按airport_id合并成两行可用sql语句 select airport_id, wmsys.wm ...
- 类型:NodeJs;问题:默认IE的编码为utf8;结果:IE不能自动选择UTF-8编码解决办法
在Windows操作系统上使用IE作为浏览器时.常常会发生这样的问题:在浏览使用UTF-8编码的网页时,浏览器无法自动侦测(即没有设定“自动选 择”编码格式时)该页面所用的编码.即使网页已经声明过编码 ...
- 用JS,打印三角形
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 修改linux内核启动logo及显示位置
转载于:http://blog.chinaunix.net/uid-28458801-id-3484269.html 在此基础上我又添加了我的一些不同的地方,仅供参考 内核版本: 2.6.35.3 l ...
- sys添加调用模块的路径;遍历可以调用模块的路径
import sys sys.path.append("D:") for i in sys.path: print(i)
- SQL基础E-R图基础
ER图分为实体.属性.关系三个核心部分.实体是长方形体现,而属性则是椭圆形,关系为菱形. ER图的实体(entity)即数据模型中的数据对象,例如人.学生.音乐都可以作为一个数据对象,用长方体来表示, ...
- 使用foreach获取数据列表的全部信息
先把代码列出来:(在admin/listAdmin.php中) <?php foreach($rows as $row):?> //注意,这里的foreach($rows as $row) ...
- ROS Learning-007 beginner_Tutorials ROS节点
ROS Indigo beginner_Tutorials-06 ROS节点 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu 14.04.4 LT ...