【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 ...
随机推荐
- fontAwesome代替网页icon小图标
引言 奥森图标(Font Awesome)提供丰富的矢量字体图标—通过CSS可以任意控制所有图标的大小 ,颜色,阴影. 网页小图标到处可见,如果一个网页都是干巴巴的文字和图片,而没有小图标,会显得非常 ...
- 2014 Super Training #6 G Trim the Nails --状态压缩+BFS
原题: ZOJ 3675 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3675 由m<=20可知,可用一个二进制数表 ...
- 深入理解maven及应用--转
(一):生命周期和插件 在项目里用了快一年的maven了,最近突然发现maven项目在eclipse中build时非常慢,因为经常用clean install命令来build项目,也没有管那么多,但最 ...
- bootstrap学习总结-css样式设计(一)
由于项目需要,所以打算好好学习下bootstrap框架,之前了解一点,框架总体不难,但涉及到的东西还是很多,想要熟练掌握它,还是要多练练. 一:bootstrap是什么? bs是什么? 即前端页面搭 ...
- JMeter学习(三十一)Access Log Sampler
前提: 在tomcat\conf\server.xml默认情况下,会有一段代码: <Valve className="org.apache.catalina.valves.Access ...
- java 21 - 3 字符输入流
所谓的输入流,就是读取文件中的数据 同样的,字符输入流InputStreamReader 4个构造方法,不过2个比较常用: 构造方法: A:InputStreamReader(InputStream ...
- Mac下Android Studio中获取SHA1和MD5
有很多人讲这个的时候,老是只把这个代码标出来又不说为什么 keytool -list -keystore debug.keystore keytool 这个是java的 jdk中一个工具(做签名文 ...
- javascript中的array对象属性及方法
Array 对象 Array 对象用于在单个的变量中存储多个值. 创建 Array 对象的语法: new Array(); new Array(size); new Array(element0, e ...
- AFN框架基本使用
0.AFN框架基本使用 0.1 AFN内部结构 AFN结构体 - NSURLConnection + AFURLConnectionOperation(已经被废弃) + AFHTTPRequestOp ...
- 在collection view中加入 NavigationController问题
在开发过程中用collectionView集合视图的时候,用navgationController跳转会出现导航栏掩盖部分内容现象, 这时候需要在viewDidLoad里面填写 self.edgesF ...