Codeforces--621B--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.
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 one integer — the number of pairs of bishops which attack each other.
5
1 1
1 5
3 3
5 1
5 5
6
3
1 1
2 3
3 5
0
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的直线,我们可以分别用他们的横截距纵截距两条线,因为斜率可以看做已知
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a[3000],b[3000];
int main()
{
long long n;
while(cin>>n)
{
if(n==0) break;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
int x,y;
for(int i=0;i<n;i++)
{
cin>>x>>y;
int ans1=x-y;
b[1000-ans1]++;
int ans2=y+x;
a[ans2-1]++;
}
__int64 sum=0;
for(int i=0;i<=3000;i++)
{
sum+=a[i]*(a[i]-1)/2;
sum+=b[i]*(b[i]-1)/2;
}
cout<<sum<<endl;
}
return 0;
}
Codeforces--621B--Wet Shark and Bishops(数学)的更多相关文章
- CodeForces 621B Wet Shark and Bishops
记录一下每个对角线上有几个,然后就可以算了 #include<cstdio> #include<cstring> #include<cmath> #include& ...
- Codeforces 612B. Wet Shark and Bishops 模拟
B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...
- codeforce 621B Wet Shark and Bishops
对角线 x1+y1=x2+y2 或者x1-y1=x2-y2 #include<iostream> #include<string> #include<algorithm& ...
- B. Wet Shark and Bishops(思维)
B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 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 ...
- 【矩阵乘法优化dp】[Codeforces 621E] Wet Shark and Blocks
http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test 2 seconds ...
- CODEFORCEs 621E. Wet Shark and Blocks
E. Wet Shark and Blocks time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 【CodeForces 621B】Wet Shark and Bishops
题 题意 1000*1000的格子里,给你n≤200 000个点的坐标,求有多少对在一个对角线上. 分析 如果求每个点有几个共对角线的点,会超时. 考虑到对角线总共就主对角线1999条+副对角线199 ...
- Codeforces Round #341 Div.2 B. Wet Shark and Bishops
题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数 由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y 然后每个数组中扫描重复数字k ans加上kC ...
- Chocolate&&木块拼接&&Cards&& Wet Shark and Bishops
B. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
随机推荐
- MyBatis入门2_增删改查+数据库字段和实体字段不一致情况
本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! 当数据库字段和实体bean中属性不一致时 之前数据库P ...
- which
功能说明:显示命令的全路径. 参数选项: -a 默认在PATH路径中由前往后查找命令,如果查找到了,就停止匹配.使用-a选项将遍历所有PATH路径,输出所有匹配项. 参数-a把所有匹配命令路 ...
- Spring Boot项目中使用 TrueLicense 生成和验证License(服务器许可)
一 简介 License,即版权许可证,一般用于收费软件给付费用户提供的访问许可证明.根据应用部署位置的不同,一般可以分为以下两种情况讨论: 应用部署在开发者自己的云服务器上.这种情况下用户通过账号登 ...
- Windows系统设置与北京Internet时间同步
找到提供Ntp服务器的网址:http://support.ntp.org/我从中找到东北大学的: ntp.neu.edu.cn ( 202.118.1.46 ) 长话短说,下面开始设置: 修改后的值 ...
- 在vue中通过js动态控制图片按比列缩放
1.html 通过外层的div来给img对应的class,隐藏的img是得到img图片请求回来时的原始尺寸.外层div是固定大小,因此,图片有两种情况去适应外部div的尺寸.一种是宽度大于高度的情况, ...
- Python 内置函数 day4
import random s = 'abczfg' st= {3,4,9,1,8} print(dir(random))#打印模块内的方法,输出模块/变量可以调用的方法 print(dir(s))# ...
- mysql在windows上安装
一.在window上安装mysql MySQL是一个小巧玲珑但功能强大的数据库,目前十分流行.但是官网给出的安装包有两种格式,一个是msi格式,一个是zip格式的.很多人下了zip格式的解压发现没有s ...
- Perl Connect to Database without password as sysdba
#!/oracle/product/11g/db/perl/bin/perl use lib '/oracle/product/11g/db/perl/lib/site_perl/5.10.0'; u ...
- / Vijos / 题库 / 1622 / 文件查找(HOI)
/ Vijos / 题库 /1622/文件查找(HOI) 描述 WINDOWS是一个很庞大的操作系统(当然啦,看占的硬盘空间就知道了),比如说,它的文件查找系统.现在,请你用PASCAL或者C或者C+ ...
- 7 numpy 傅里叶,提取图片轮廓
任务:提取照片中轮廓 本次处理图片:我的女神之一 江一燕 导入模块: #jyy.show() 会打开本地图片浏览器 使用傅里叶反转 获取实部,舍弃虚部 去除小数部分 将一维数 ...