hdu 4007 Dave(线性探查+枚举)
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).
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 the largest number of people in a square with the length of R.
If two people stand in one place, they are embracing.
题目意思:
给你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(线性探查+枚举)的更多相关文章
- HDU 4007 Dave(离散化)
Dave Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submis ...
- hdu 4007 Dave (2011年大连ACM网络赛)
题意:给定正方形的边长 r ,在平面内寻找正方形可以圈住的点的最大的个数. 分析:先对点排序,然后固定一条边,再平移另一条垂直边,得到点的个数,最后比较大小即可. 注意:不包含正方形倾斜的情况! // ...
- HDU 5778 abs (枚举)
abs 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5778 Description Given a number x, ask positive ...
- 2015多校第6场 HDU 5358 First One 枚举,双指针
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5358 题意:如题. 解法:观察式子发现,由于log函数的存在,使得这个函数的值域<=34,然后我 ...
- HDU 4587 TWO NODES 枚举+割点
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 TWO NODES Time Limit: 24000/12000 MS (Java/Other ...
- hdu 5289 rmp+二分+枚举后界 or单调队列 ****
好题~~ 给你n个数和k,求有多少的区间使得区间内部任意两个数的差值小于k,输出符合要求的区间个数,枚举后界~~ 又是一种没见过的方法,太弱了/(ㄒoㄒ)/~~ #include <cstdio ...
- HDU 5358 尺取法+枚举
题意:给一个数列,按如下公式求和. 分析:场上做的时候,傻傻以为是线段树,也没想出题者为啥出log2,就是S(i,j) 的二进制表示的位数.只能说我做题依旧太死板,让求和就按规矩求和,多考虑一下就能发 ...
- HDU 4445 Crazy Tank --枚举
题意: n个物体从高H处以相同角度抛下,有各自的初速度,下面[L1,R1]是敌方坦克的范围,[L2,R2]是友方坦克,问从某个角度抛出,在没有一个炮弹碰到友方坦克的情况下,最多的碰到敌方坦克的炮弹数. ...
- HDU 4705 Y 树形枚举
树形枚举--搜索 题目描述: 给你一棵树,要在一条简单路径上选3个不同的点构成一个集合,问能构成多少个不同的集合. 解法: 枚举所有结点,假设某个结点有n棵子树,每棵子树的结点个数分别为s1,s2,` ...
随机推荐
- [Javascript] lodash: memoize() to improve the profermence
Link: https://lodash.com/docs#memoize Example: .service('UserPresenter', function(UserConstants){ va ...
- [RxJS] Handling Multiple Streams with Merge
You often need to handle multiple user interactions set to different streams. This lesson shows hows ...
- 基于注解的Spring MVC
1.加入�jar 2.web.xml配置: <?xml version="1.0" encoding="UTF-8"?> <web-app v ...
- PHP5生成图形验证码(有汉字)
利用PHP5中GD库生成图形验证码 类似于下面这样 1.利用GD库函数生成图片,并在图片上写指定字符 imagecreatetruecolor 新建一个真彩色图像 imagecolora ...
- setTimeout()和setInterval()小结
写在前面:在写H5游戏时经常需要使用定时刷新页面实现动画效果,比较常用即setTimeout()以及setInterval() setTimeout 描述 setTimeout(code,millis ...
- Android 打造任意层级树形控件 考验你的数据结构和设计
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/40212367,本文出自:[张鸿洋的博客] 1.概述 大家在项目中或多或少的可能会 ...
- Hacker(16)----防范端口扫描与嗅探
端口扫描与嗅探都是黑客常用的招数,其目的是定位目标计算机和窃取隐私信息.为确保自己计算机的安全,用户需要掌握防范嗅探与端口扫描的常见措施,保障个人隐私信息安全. 一.掌握防范端口扫描的常用措施 防范端 ...
- WPF XAML之bing使用StringFormat(转)
释义 BindingBase.StringFormat 属性 获取或设置一个字符串,该字符串指定如果绑定值显示为字符串,应如何设置该绑定的格式. 命名空间: System.Windows ...
- 常用SQL语句学习整理
增 insert into table_name (column_name1,column_name2) values (value1,value2) 删 delete from table_name ...
- java实现简单的单点登录
java实现简单的单点登录 摘要:单点登录(SSO)的技术被越来越广泛地运用到各个领域的软件系统当中.本文从业务的角度分析了单点登录的需求和应用领域:从技术本身的角度分析了单点登录技术的内部机制和实现 ...