Codeforces Round #341 (Div. 2)B
2 seconds
256 megabytes
standard input
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 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上攻击)
输入n个象 判断有多少种攻击配对
题解: 斜率为1的 x-y的值相同
斜率为-1的x+y的值相同 (都在同一对角线上)
数组标记 或map标记
每条线上的配对数量 fun()实现
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
int flag[4005];
int flag1[4005];
ll fun(ll n,ll m)
{
ll sum=1;
for(ll i=1,j=n;i<=m;i++,j--)
sum=sum*j/i;
return sum;
}
int main()
{
ll x,y,z,i;
scanf("%I64d",&x);
for(i=0;i<x;i++)
{
scanf("%I64d%I64d",&y,&z);
flag[y+z]++;
flag1[y-z+1000]++;
}
ll ans=0;
for(i=0;i<=3000;i++)
{
if(flag[i])
ans+=fun(flag[i],2);
if(flag1[i])
ans+=fun(flag1[i],2);
}
printf("%I64d\n",ans);
return 0;
}
Codeforces Round #341 (Div. 2)B的更多相关文章
- Codeforces Round #341 (Div. 2) E. Wet Shark and Blocks dp+矩阵加速
题目链接: http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test2 se ...
- Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese 数学
D. Rat Kwesh and Cheese 题目连接: http://www.codeforces.com/contest/621/problem/D Description Wet Shark ...
- Codeforces Round #341 Div.2 D. Rat Kwesh and Cheese
嗯本来想着直接算出来不就行了吗 然后我想到了200^200^200....... 好吧其实也不难取两次log就行了 然后我第一次写出来log就写残了........... log里面的拆分要仔细啊.. ...
- Codeforces Round #341 Div.2 C. Wet Shark and Flowers
题意: 不概括了..太长了.. 额第一次做这种问题 算是概率dp吗? 保存前缀项中第一个和最后一个的概率 然后每添加新的一项 就解除前缀和第一项和最后一项的关系 并添加新的一项和保存的两项的关系 这里 ...
- Codeforces Round #341 Div.2 B. Wet Shark and Bishops
题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数 由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y 然后每个数组中扫描重复数字k ans加上kC ...
- Codeforces Round #341 (Div. 2)
在家都变的懒惰了,好久没写题解了,补补CF 模拟 A - Wet Shark and Odd and Even #include <bits/stdc++.h> typedef long ...
- Codeforces Round #341 Div.2 A. Wet Shark and Odd and Even
题意是得到最大的偶数和 解决办法很简单 排个序 取和 如果是奇数就减去最小的奇数 #include <cstdio> #include <cmath> #include < ...
- Codeforces Round #341 (Div. 2) ABCDE
http://www.cnblogs.com/wenruo/p/5176375.html A. Wet Shark and Odd and Even 题意:输入n个数,选择其中任意个数,使和最大且为奇 ...
- Codeforces Round #341 (Div. 2) E - Wet Shark and Blocks
题目大意:有m (m<=1e9) 个相同的块,每个块里边有n个数,每个数的范围是1-9,从每个块里边取出来一个数组成一个数,让你求组成的方案中 被x取模后,值为k的方案数.(1<=k< ...
- Codeforces Round #341 (Div. 2) C. Mike and Chocolate Thieves 二分
C. Mike and Chocolate Thieves time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
随机推荐
- Oracle作业练习题
第一问 //登陆scott用户 //解锁 alter user scott account unlock; //给用户申请密码 alter user scott identified by tiger ...
- Ubuntu14.04 panic --not syncing: Attempt to kill init 解决方法
Ubuntu14.04 panic --not syncing: Attempt to kill init 解决方法 工作电脑装了一个虚拟机玩玩,胡乱下载了一些软件,apt-get了不少操作,后来重启 ...
- post接口_form表单上传
上传文件的本质是浏览器读取本地文件的内容,以二进制数据方式传输到服务端,服务端新建一个文件,将获取到的数据复制到文件中 LR中上传操作可以通过web_submit_data函数实现,支持录制要点:we ...
- 今日头条 2018 AI Camp 5 月 26 日在线笔试编程题第一道——最佳路径
题目 给定一个 n*m 的矩阵 A ,矩阵中每一个元素为一个十六进制数.寻找一条从左上角都右下角的路径,每次只能向右或者向下移动, 使得路径上所有数字之积在 16 进制下的后缀 0 最少. 输入描述: ...
- MyEclipse2013使用总结
1.myeclipse10中怎样将建的包设置成树形结构或者并列结构. 右上边三角那里进去设置选第一个是显示完整的包名,第二个显示的是树形结构这种方法没效 2.从高版本到项目的低版本的MyEclipse ...
- Java常用类之Math类
Java 的常用类Math类: java.lang.Math 提供了系列的静态方法用于科学计算,其方法的参数和返回值类型一般为 double 类型. 如: 1. public static final ...
- Swift-元祖
1.元组是多个值组合而成的复合值.元组中的值可以是任意类型,而且每一个元素的类型可以是不同的. let http404Error = (,"Not Found") print(ht ...
- 3DMAX2016安装教程【图文】
下载安装包之后,双击setup.exe. 下面是安装图片教程: 点击安装 点击下一步. 如图输入序列号和产品密钥. 填写安装路径,然后下一步. 开始安装,等待. 安装成功.
- 软工网络15团队作业4——Alpha阶段敏捷冲刺-1
各个成员在 Alpha 阶段认领的任务 成员 Alpha 阶段认领的任务 肖世松 编写界面设计代码 杨泽斌 服务器连接与配置 叶文柠 数据库连接与配置 谢庆圆 编写功能板块代码 林伟航 编写功能板块代 ...
- Qt自定义标题栏
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt自定义标题栏 本文地址:http://techieliang.com/2017/1 ...