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. java 实例化是调用了子类重写方法

    java 实例化时调用了抽象方法或者class里面某个方法,如果子类有重写改方法,实际运行的是子类重写方法 package auto.test; //抽象父类 public abstract clas ...

  2. testng 提供参数

    获取页面元素属性,并把属性作为参数传递个测试方法,两桶不同的写法 1. @DataProvider public Iterator<Object[]> dp() { mySleep(500 ...

  3. 响应式布局:Flexbox应用总结

    距离上篇文章<布局神器:Flexbox>的发表已有一周时间,转眼这周又到了周五(O(∩_∩)O~~): 习惯性在周五对自己的一周工作进行下总结,记录下这周值得被纪念的工作事件,无论是好的, ...

  4. Android + eclipse +ADT安装完全教程

    最近几天没事做,网上看来看去突然就想弄个android来学学...  首先,是要下载android SDK,在http://developer.android.com/sdk/index.html这个 ...

  5. Three Families

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  6. [RxJS] Reactive Programming - Rendering on the DOM with RxJS

    <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery- ...

  7. asp.net操作xml(增删查改)

    asp.net操作xml 1.xml文档Products.xml <?xml version="1.0" encoding="utf-8"?> &l ...

  8. 外观模式-facade实现interface的方式(简单工厂+facade组合使用)

    Façade 外观模式 1.Façade实现为interface的具体过程 在Façade.java 接口 工厂 将构造方法私有  static 方法产生一个工厂 此时 客户端不知道 Façade的存 ...

  9. HTTP get、post请求

    Post请求: string postData = "user=123&pass=456"; // 要发放的数据 byte[] byteArray = Encoding.U ...

  10. web开发常用样式

    1.div保持底部浮动(不受滚动条影响) position:fixed;_position:absolute;bottom:0px;_bottom:0px;_margin-top:expression ...