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) (<=x, y<=) coordinates of people. 
Output
Output the largest number of people in a square with the length of R.
 
Sample Input

 
Sample Output

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

题目意思:

给你N个点和一个边长为R的正方形,为你用这个正方形最多可以覆盖几个点(在正方形边界上的点也算)。

 

注意:正方形的边一定平行于坐标轴。

 

思路:

对N个点的y坐标进行排序,然后O(N)枚举正方形的下边界。取出N个点中y坐标在上下边界范围内的点。然后O(N)复杂度求出长度为R的边最多可以覆盖的点。所以整体枚举的复杂度为O(N^2)。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stdlib.h>
#include<map>
using namespace std;
#define inf 1<<30
#define N 1006
int n,r;
struct Node{
int x,y;
}p[N];
int yy[N];
int xx[N];
int main()
{
while(scanf("%d%d",&n,&r)==){
for(int i=;i<n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
yy[i]=p[i].y;
}
sort(yy,yy+n); int ans=;
for(int i=;i<n;i++){
//int y=yy[i];
int xcnt=;
for(int j=;j<n;j++){
if(p[j].y<=yy[i]+r && p[j].y>=yy[i]){
xx[xcnt++]=p[j].x;
}
}
sort(xx,xx+xcnt); int e=;
//xx[xcnt++]=inf;
for(int j=;j<xcnt;j++){
while(xx[e]-xx[j]<=r && e<xcnt) e++;
ans=max(ans,e-j);
} }
printf("%d\n",ans); }
return ;
}

hdu 4007 Dave(线性探查+枚举)的更多相关文章

  1. HDU 4007 Dave(离散化)

    Dave Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submis ...

  2. hdu 4007 Dave (2011年大连ACM网络赛)

    题意:给定正方形的边长 r ,在平面内寻找正方形可以圈住的点的最大的个数. 分析:先对点排序,然后固定一条边,再平移另一条垂直边,得到点的个数,最后比较大小即可. 注意:不包含正方形倾斜的情况! // ...

  3. HDU 5778 abs (枚举)

    abs 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5778 Description Given a number x, ask positive ...

  4. 2015多校第6场 HDU 5358 First One 枚举,双指针

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5358 题意:如题. 解法:观察式子发现,由于log函数的存在,使得这个函数的值域<=34,然后我 ...

  5. HDU 4587 TWO NODES 枚举+割点

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 TWO NODES Time Limit: 24000/12000 MS (Java/Other ...

  6. hdu 5289 rmp+二分+枚举后界 or单调队列 ****

    好题~~ 给你n个数和k,求有多少的区间使得区间内部任意两个数的差值小于k,输出符合要求的区间个数,枚举后界~~ 又是一种没见过的方法,太弱了/(ㄒoㄒ)/~~ #include <cstdio ...

  7. HDU 5358 尺取法+枚举

    题意:给一个数列,按如下公式求和. 分析:场上做的时候,傻傻以为是线段树,也没想出题者为啥出log2,就是S(i,j) 的二进制表示的位数.只能说我做题依旧太死板,让求和就按规矩求和,多考虑一下就能发 ...

  8. HDU 4445 Crazy Tank --枚举

    题意: n个物体从高H处以相同角度抛下,有各自的初速度,下面[L1,R1]是敌方坦克的范围,[L2,R2]是友方坦克,问从某个角度抛出,在没有一个炮弹碰到友方坦克的情况下,最多的碰到敌方坦克的炮弹数. ...

  9. HDU 4705 Y 树形枚举

    树形枚举--搜索 题目描述: 给你一棵树,要在一条简单路径上选3个不同的点构成一个集合,问能构成多少个不同的集合. 解法: 枚举所有结点,假设某个结点有n棵子树,每棵子树的结点个数分别为s1,s2,` ...

随机推荐

  1. 优化移动体验的HTML5技巧

    简介 连轴转的刷新,不断变向的页面转换,以及tap事件的周期性的延迟仅仅是现在移动web环境令人头疼事情的一小部分.开发者正试图尽可能的靠近原生应用,但却经常被各种兼容问题,系统复位,和僵化的框架打乱 ...

  2. Android调用系统邮件类应用的正确实现方法

    Android应用开发中,很多情况下免不了要调用手机上的邮件类应用,实现邮件发送的功能,这一般是通过调用系统已有的Intent来实现的.看到网上很多邮件发送都是调用action为android.con ...

  3. 解决vsftpd 530 Permission denied报错

    虚拟机装好RedHat后,准备使用filezilla连接,输入IP地址,root用户,密码,快速连接,报错: 故障排除: 1.首先检查系统是否开启了vsftp服务,如果没有开启,先开启该服务. 方法1 ...

  4. RHEL-resolv.conf文件修改后重启被还原

    修改resolve.conf文件之后,reboot或service restart network时,修改的内容被还原.关闭NetworkManager即可.# chkconfig |grep Net ...

  5. .net学习体会

    莫名其妙学了IT,在课堂上学了C,C++,自学了C#,也做了一些网站项目,学习过程,写了厚厚的几本笔记本,却没写博文的习惯,前几天,有同学问学习.net的建议.其实我懂的也不多,也给了一些个人见解,主 ...

  6. .NET 4.0 兼容 .NET 2.0 的方法

    使用.net开发桌面应用,广大亲门最头疼的莫过于客户端部署的问题.基于.net 2.0 的winfrom程序因为 Framework 的分发包大小为20M左右还好解决,不幸的是如果项目中使用了Wcf, ...

  7. linux syslog详解

    linux syslog详解 分三部分 一.syslog协议介绍 二.syslog函数 三.linux syslog配置   一.syslog协议介绍 1.介绍 在Unix类操作系统上,syslog广 ...

  8. oracle 存储过程返回结果集 (转载)

    好久没上来了, 难道今天工作时间稍有空闲, 研究了一下oracle存储过程返回结果集. 配合oracle临时表, 使用存储过程来返回结果集的数据读取方式可以解决海量数据表与其他表的连接问题. 在存储过 ...

  9. silverlight 打印

    加引用: using System.Windows.Printing; xaml文件里: //定义图片和文本打印变量  PrintDocument printImage; public BeginCo ...

  10. MD5 Tool 工具类

    package com.example.secret.tools; import java.io.UnsupportedEncodingException; import java.security. ...