题意

1000*1000的格子里,给你n≤200 000个点的坐标,求有多少对在一个对角线上。

分析

考虑到对角线总共就主对角线1999条+副对角线1999条,我们可以求每个对角线有几对点。

同一条主对角线上的元素有a[i]个,就有C(a[i],2)对点;

同一条副对角线上的元素有b[i]个,就有C(b[i],2)对点。

读入x和y后,

x+y相同的就在同一副对角线,x+y范围是(2,2000),

x-y相同的就是同一主对角线,x-y范围是(-999,999),加上1001就是(2,2000)了

x+y==2和2000的对角线只有一个元素,x-y+1000==2和2000的只有一个元素,所以只要求x+y==2到1998,和x-y+1001==2到1998的对角线。

这样就可以每次计算a[i]和b[i]的对角线有几对点,i=2到1998

AC的代码

#include <stdio.h>
#define N 2005
long long n,x,y,a[N],b[N],ans;
int main()
{
scanf("%I64d",&n);
for(int i=; i<=n; i++)
{
scanf("%I64d%I64d",&x,&y);
a[x-y+]++;
b[x+y]++;
}
for(int i=; i<=; i++)ans+=a[i]*(a[i]-)/+b[i]*(b[i]-)/;
printf("%I64d",ans);
return ;
}

【CodeForces 621B】Wet Shark and Bishops的更多相关文章

  1. 【38.24%】【codeforces 621E】 Wet Shark and Blocks

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【CodeForces 621A】Wet Shark and Odd and Even

    题 Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wan ...

  3. 【CodeForces 621C】Wet Shark and Flowers

    题 There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such tha ...

  4. Codeforces 612B. Wet Shark and Bishops 模拟

    B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  5. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  6. B. Wet Shark and Bishops(思维)

    B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. 【29.89%】【codeforces 734D】Anton and Chess

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【17.00%】【codeforces 621D】Rat Kwesh and Cheese

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 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 ...

随机推荐

  1. UESTC 882 冬马党 --状压DP

    定义:dp[i][j]为状态为j时,第i行符合条件的状态数 转移方程:dp[i][j] += dp[i-1][t]   //t为上一行状态,与当前行不冲突. 从第一行开始向下枚举,每次枚举当前行的状态 ...

  2. Redis安装,mongodb安装,hbase安装,cassandra安装,mysql安装,zookeeper安装,kafka安装,storm安装大数据软件安装部署百科全书

    伟大的程序员版权所有,转载请注明:http://www.lenggirl.com/bigdata/server-sofeware-install.html 一.安装mongodb 官网下载包mongo ...

  3. 深入.NET框架 项目《魔兽登录系统》

    创建魔兽系统相关窗体: 登录窗体(frmLogin) 注册窗体(frmRegister) 主窗体   (frmMain) 实现魔兽登录系统: 登录的界面如下 实现思路: 1.创建一个对象数组,长度为1 ...

  4. android初学问题集

    1. Manifest中的Application tag用途? 2. java中的组件设计模型是指什么? 3. java Bean是指什么? 4. Proxy-Stub设计模式又指的是什么? 有要的网 ...

  5. mysqli_stmt预处理类

    <?php  $mysqli=new mysqli("localhost", "root", "123456", "xsph ...

  6. mysql完整备份时过滤掉某些库

    mysql进行完整备份时使用--all-database参数比如:#mysqldump -u root -h localhost -p --all-database > /root/all.sq ...

  7. kvm虚拟化管理平台WebVirtMgr部署-完整记录(安装Windows虚拟机)-(4)

    一.背景说明  在之前的篇章中,提到在webvirtmgr里安装linux系统的vm,下面说下安装windows系统虚拟机的操作记录: 由于KVM管理虚拟机的硬盘和网卡需要virtio驱动,linux ...

  8. 课程1——数据类型和变量

    声明:本系列随笔主要用于记录c语言的常备知识点,不能保证所有知识正确性,欢迎大家阅读.学习.批评.指正!!你们的鼓励是我前进的动力.严禁用于私人目的.转载请注明出处:http://www.cnblog ...

  9. 跳台阶 一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。

    class Solution { public: int jumpFloor(int number) { ) ; ) ; )+jumpFloor(number-); } }; 如果先建立数组,然后利用 ...

  10. SRTM数据介绍与说明

    一.SRTM 的背景引言 美国利用航天飞机搭载成像雷达对地进行观测始于20 世纪80 年代初.1982 年11 月和1985 年10 月, 美国分别进行了两次称为S IR2A 与S IR2B 的航天飞 ...