Dave

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 3524    Accepted Submission(s): 1183

Problem Description
Recently, Dave is boring, so he often walks around. He finds that some places are too crowded, for example, the ground. He couldn't help to think of the disasters happening recently. Crowded place is not safe. He knows there are N (1<=N<=1000) people on the ground. Now he wants to know how many people will be in a square with the length of R (1<=R<=1000000000). (Including boundary).
 
Input
The input contains several cases. For each case there are two positive integers N and R, and then N lines follow. Each gives the (x, y) (1<=x, y<=1000000000) coordinates of people. 
 
Output
Output the largest number of people in a square with the length of R.
 
Sample Input
3 2
1 1
2 2
3 3
 
Sample Output
3

Hint

If two people stand in one place, they are embracing.

 
Source
 
题解:这个题是要求正方形与坐标轴平行;可以先确定对于x满足的点数,再找y;可以二分找;
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAXN = ;
typedef long long LL;
struct Point{
int x, y;
friend bool operator < (Point a, Point b){
return a.x < b.x;
}
};
Point dt[MAXN];
int p[MAXN];
int main(){
int N, R;
while(~scanf("%d%d", &N, &R)){
for(int i = ; i < N; i++){
scanf("%d%d", &dt[i].x, &dt[i].y);
}
sort(dt, dt + N);
int ans = ;
for(int i = ; i < N; i++){
int tp = ;
p[tp++] = dt[i].y;
for(int j = i + ; j < N; j++){
if(dt[j].x - dt[i].x > R)
break;
p[tp++] = dt[j].y;
}
sort(p, p + tp);
for(int l = ; l < tp; l++){
int cnt = upper_bound(p + l, p + tp, p[l] + R) - (p + l);
ans = max(ans, cnt);
}
}
printf("%d\n", ans);
}
return ;
}

Dave(正方形能围成的最大点数)的更多相关文章

  1. Agent J(求三个圆围成的区域面积)

    A - A Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status P ...

  2. LeetCode 85 | 如何从矩阵当中找到数字围成的最大矩形的面积?

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题53篇文章,我们一起来看看LeetCode中的85题,Maximal Rectangle(最大面积矩形). 今天的 ...

  3. 求曲线y=lnx在区间(2,6)内的一条切线,使得该切线与直线x=2,x=6及曲线y=lnx所围成的图形的面积最小。

    求曲线y=lnx在区间(2,6)内的一条切线,使得该切线与直线x=2,x=6及曲线y=lnx所围成的图形的面积最小. 1.先画图. 2.设切点为(a,lna) (2<a<6) 3.切线方程 ...

  4. 多个n维向量围成的n维体积的大小

    前言 上周我们数学老师给了我们一道题,大意就是两个向量a和b,一个点M=$x*a+y*b$,x,y有范围,然后所有M组成的面积是一个定值,求x+y的最小值.当然这是道小水题,但我在想,如果把两个向量变 ...

  5. uva11178 Morley’s Theorem(求三角形的角三分线围成三角形的点)

    Morley’s Theorem Input: Standard Input Output: Standard Output Morley’s theorem states that that the ...

  6. 微信小程序canvas把正方形图片绘制成圆形

    wxml代码: <view class="result-page"> <canvas canvas-id='firstCanvas' style='width:1 ...

  7. n阶方阵,数字从1~n^2,顺时针增大

    运行结果如下图: 解题思路:可以将这个问题分解成x个外围正方形所围成的图形,外围的正方形又可以分为4个步骤,向右依次增大.向下依次增大.向左依次增大.向上依次增大.基本思路就是如此,最关键的就是什么时 ...

  8. HDU 4739 求正方形个数

    九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/11711707 求所有可能围成的正方形,借个代码 #include <que ...

  9. 用初中代数结合python画出正方形

    在屏幕上打印类似下面的图形: 常规画正方形的算法: 这几乎是初学所有计算机语言时都会遇到的问题.算法都大致类似,就是找出打印规律然后用计算机语句表达出来.最常规的算法是:输入数字n就打印n行,首行和尾 ...

随机推荐

  1. junit4测试 Spring MVC注解方式

    本人使用的为junit4进行测试 spring-servlet.xml中使用的为注解扫描的方式 <?xml version="1.0" encoding="UTF- ...

  2. JSP中getParameter和getAttribute区别

    (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter ...

  3. 转载: Javah生成JNI头文件出现找不到类的错误

    错误: 找不到 'com.chnic.jni.SayHellotoCPP' 的类文件. 上图可以看到错误和解决办法. 不要忘记那个点 javah -classpath . -jni com.chnic ...

  4. 获取Excel表中各个Sheet的方法

    获取Excel表中各个Sheet的方法 private void simpleButton2_Click(object sender, EventArgs e) { OfdBOM.Filter = & ...

  5. (转)一小时搞定DIV+CSS布局-固定页面开度布局

    本文讲解使用DIV+CSS布局最基本的内容,读完本文你讲会使用DIV+CSS进行简单的页面布局. 转载请标明:http://www.kwstu.com/ArticleView/divcss_20139 ...

  6. Android SDK离线安装

    Android SDK离线安装是本文要介绍的内容,主要是来了解并学习Android SDK安装的内容,具体关于Android SDK是如何离线安装的内容来看本文详解. Android开发环境,完整的说 ...

  7. Solr-4.10.2与Tomcat整合

    1.将下载的solr解压至D:\solr,拷贝d:\solr\solr-4.10.2\example\webapps\solr.war到Tomcat的webapps\目录中.直接解压 solr.war ...

  8. gitweb随记

    1.安装gitweb,命令安装即可 apt-get install gitweb 2.clone cgi $ git clone git://git.kernel.org/pub/scm/git/gi ...

  9. C/C++中的成员函数指针声明及使用

    代码: #include <iostream> using namespace std; class Test{ public: void func(){ cout<<&quo ...

  10. RCP打包出来 运行 出现 JVM terminated.exit code = 13

    在建立PM.product,即打包时,没有添加相应的插件,导致无法运行