题意

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. bootstrap学习总结-css样式设计(二)

    首先,很感谢各位园友对我的支持,关于bootstrap的学习总结,我会持续更新,如果有写的不对的地方,麻烦各位给我指正出来哈.关于上篇文章,固定布局和流式布局很关键,如果还不太清楚的可以再看看我写的h ...

  2. Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)

    ​[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...

  3. ST3插件——PlainTasks的使用

    今天看到一个有意思的ST3插件,可以进行简单的任务管理. 安装很简单:ctrl + shift + p,输入install回车,再输入plaintasks回车即可. 以下是一些支持的操作,更多的操作请 ...

  4. 关闭linux centos各种声音

    shell报警 #vi /etc/inputrc ================================ set bell-style none 或 echo "set bell- ...

  5. 模拟alert和confirm

    啥也不说,先上图,有图有真相 :) 现在绝大多数网站都不用自带的alert和confirm了,因为界面太生硬了.因此这个插件就这样产生了... 来看插件的实现代码吧: (function () { $ ...

  6. C# MD5加密解密帮助类

    /// <summary>    /// MD5加密解密帮助类    /// </summary>    public static class DESHelper    {  ...

  7. VS2013中BOOST库的环境配置与使用

    &1 安装Boost 文件下载:链接:http://pan.baidu.com/s/1kUKaOFP 密码:auf2 解压之后放到你想安装的文件夹内,我的是在C:\Program Files\ ...

  8. 【兄弟连】2016高洛峰新版PHP培训视频教程

    [兄弟连]2016高洛峰新版PHP培训视频教程                                                            视频部分目录: 下载地址:http ...

  9. 从0开始学Java——JSP&Servlet——HttpServletRequest相关的几个路径信息

    在HttpServletRequest中有几个获取路径的接口:getRequestURI/getContextPath/getServletPath/getPathInfo 这些接口互相之间有什么区别 ...

  10. [MetaHook] Quake FMOD function

    QFMOD.h #ifndef QFMOD_H #define QFMOD_H #include "fmod.h" extern FMOD_RESULT (F_API *qFMOD ...