【CodeForces 621B】Wet Shark and Bishops
题意
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的更多相关文章
- 【38.24%】【codeforces 621E】 Wet Shark and Blocks
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【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 ...
- 【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 ...
- Codeforces 612B. Wet Shark and Bishops 模拟
B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- B. Wet Shark and Bishops(思维)
B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 【29.89%】【codeforces 734D】Anton and Chess
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【17.00%】【codeforces 621D】Rat Kwesh and Cheese
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 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 ...
随机推荐
- SQL里面如何取得前N条数据?
select * from table order by id limit 10 运用limit可以获取前N个数据
- Flex xml编辑器(老外写的)
github上的一个项目老外写的xml编辑器,灵活利用了Tree的labelFunction实现节点运行时展现.开源地址是 https://github.com/softinsure/XML-Edit ...
- mysql乱码的好文
1. http://www.blogjava.net/wldandan/archive/2007/09/04/142669.html 2. http://www.111cn.net/database/ ...
- 对访问修饰关键字public, protected, internal and private的说明
对访问修饰关键字public, protected, internal and private的说明1.msdn: Internal types or members are accessible o ...
- 转 异常处理汇总 ~ 修正果带着你的Net飞奔吧!
异常处理汇总 ~ 修正果带着你的Net飞奔吧! 异常处理汇总-服 务 器 http://www.cnblogs.com/dunitian/p/4522983.html 异常处理汇总-开发工具 h ...
- js中接口的声明与实现
实现接口,必须实现接口里的所有方法. function Interface(name,fns){//声明一个接口类 this.name = name; th ...
- ES6新增const常量、let变量
JavaScript 严格模式(use strict) 严格模式下你不能使用未声明的变量. const c1 = 1; const c2 = {}; const c3 = []; 不能对c1的值进行再 ...
- 一段后台C#查询SQL Server数据库代码
using System; using System.Data; using System.Collections.Generic; using System.Linq; using System.W ...
- 在ASP.Net和IIS中删除不必要的HTTP响应头
引入 每次当浏览器向Web服务器发起一个请求的时,都会伴随着一些HTTP头的发送.而这些HTTP头是用于给Web服务器提供一些额外信息以便于处理请求.比如说吧.如果浏览器支持压缩功能,则浏览器会发送A ...
- Android 动画之AlphaAnimation应用详解
窗口的动画效果,淡入淡出什么的,有些游戏的欢迎动画,logo的淡入淡出效果就使用AlphaAnimation.AlphaAnimation(0.01f, 1.0f); 从0.01f到1.0f渐变.学过 ...