题意

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. FreeMarker 一二事 - 静态模板结合spring展示

    freemarker可以脱离web使用 前一篇文章使用了普通的方法 这回说说结合spring pom额外引入这个jar包 <dependency> <groupId>org.s ...

  2. 程序4-5 打开一个文件,然后unlink

    //http://blog.chinaunix.net/uid-24549279-id-71355.html /* ========================================== ...

  3. JQuery[一] 中如何选中$(this)下面的子元素

    <ul> li><span></span></li> li><span></span></li> < ...

  4. Xcode视图调试

    视图调试 使用视图调试器检查您的视图层次结构,可以轻松地判断视图位置.大小以及实现问题. 在XCode中运行你的应用程序,在调试栏上点击“调试视图层次”按钮,进入视图调试器. XCode停止你的应用程 ...

  5. css继承性和不继承的属性。

    在CSS中并不是所有的属性都是能够继承的,因此在使用时一定要了解哪些是能够继承的哪些是不能够继承的.visibility和cursor能够被所有元素继承:letter-spacing,word-spa ...

  6. 09SpringMvc_再次讲一下SpringMvc的工作流:

    整个SpringMvc的流程图:

  7. 卫星轨道和两行数据TLE

    最近由于Sino-2和北斗的关系,很多网友贴了表示卫星运行轨道的TLE数据.这里想对卫星轨道参数和TLE的格式做一个简单介绍.虽然实际上没有人直接读TLE数据,而都是借助软件来获得卫星轨道和位置信息, ...

  8. IBatis.Net学习笔记十三:在IBatis.Net中调用存储过程

    其实调用方式比较简单,主要也就是两种类型的存储过程:1.更新类型的存储过程2.查询类型的存储过程下面就来看看具体的调用方式:1.更新类型的存储过程sp_InsertAccount: CREATE PR ...

  9. matlab取消和添加注释以及一些快捷键

    1 matlab中关于注释: 多行注释: 选中要注释的若干语句,工具栏菜单Text->Comment,或者鼠标右击选"Comment",或者快捷键Ctrl+R 取消注释: 选 ...

  10. java资源下载之官网地址

    [一].json下载地址 http://sourceforge.net/projects/json-lib/files/ [二].apache-commons下载地址 http://commons.a ...