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 ...
随机推荐
- jQuery判断 form表单提交时一些文本框的判断
一: form表单提交时如果表单里有input标签为空那么不提交form表单. <head> <script type="text/javascript"> ...
- 技术总监Sycx的故事
其实我在各种演讲里,线下吹牛里面无数次提及过他,讲过他的故事,但是总还是没有任何一次认认真真的详细讲过,所以,今天就讲讲他的故事吧. Sycx是福建漳州人,我经常开玩笑说,你生于一个著名的骗子之乡,为 ...
- Order By操作
本文转载自:http://www.cnblogs.com/vingi/articles/2450482.html 适用场景:对查询出的语句进行排序,比如按时间排序等等. 说明:按指定表达式对集合排序: ...
- Java-API-Package:java.lang
ylbtech-Java-API-Package:java.lang 1.返回顶部 1. Package java.lang Provides classes that are fundamental ...
- 解决webpack因新版本打包失败问题--ERROR in multi ./src/main.js ./dist/bundle.js
最近在学习webpack打包过程中遇到的一个问题向大家分享下! 创建了一个webpacksty的目录,目录下放着dist,src子目录,然后通过node环境下,npm init -y 初始化项目出现p ...
- CSS2实用知识点详解
CSS相关知识回顾目录 CSS2选择器 假选择器的使用 属性选择器的使用 边框设置 背景设置 字体设置 文本属性 a标签假选择器使用 列表设置 表格设置 鼠标设置 单位设置 隐藏显示 位置设置 清除浮 ...
- Oracle 10g RAC全库flashback
因业务原因,今天需要做一次全库flashback.以下是操作全过程: 1.确认主库是否能flashback到需要的时间点 在节点1上执行: SQL> alter session set nls_ ...
- tomcat是一个应用服务器
总的来说,tomcat的身份可以看作一个WEB容器,但实际上是一个应用程序服务器.为什么这么说?1.因为你从tomcat内部看你会发现其实tomcat内置了一个轻量级的WEB服务器,用于转发html文 ...
- matlab学习笔记(4)
第9章 数学建模函数 曲线拟合: 多项式拟合: polyfit()函数:采用最小二乘法进行多项式拟合. polyfit(x,y,n); %对于数据集[x,y],找到次数为n的多项式. [p E] ...
- HDU 4921 Map(状态压缩)
题意看这篇博客. 思路参考的这篇博客. 补充:面对这种问题有一个常见的套路.比如计算若干个区间对答案的贡献这种问题,直接暴力可能复杂度到O(n ^ 2), 而我们可以计算出每个元素在多少个合法区间中, ...