HDU 4007:Dave (枚举)
来源:互联网 发布:java服务器插件 编辑:程序博客网 时间:2024/06/05 01:04
Dave
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
题意:
现在给出n个点的坐标,然后要我们画一个边长为R的正方形,使得这个正方形中的点最多。
解题思路:
枚举每个点的y坐标,作为上界,那么y+R就是其下界,在其中统计在这个范围中的x,排序后,另一个循环枚举x的左右边界。复杂度应该是O(N^2logN)。
Code:
#include <iostream>#include <cmath>#include <cstdio>#include <algorithm>#include <cstring>#include <stdlib.h>#define mem(a,b) memset(a,b,sizeof(a))using namespace std;typedef long long LL;const int INF=3e9;const int maxn=1005;struct Node{ int x,y;}p[maxn];bool cmp(Node a,Node b){ return a.y<b.y;}int xx[maxn];int main(){ int n,r; while(scanf("%d%d",&n,&r)!=EOF) { for(int i=0;i<n;i++) { scanf("%d%d",&p[i].x,&p[i].y); } int ans=0; sort(p,p+n,cmp); for(int i=0;i<n;i++) { int L=p[i].y,R=p[i].y+r; int len=0; for(int j=0;j<n;j++) { if(p[j].y>=L&&p[j].y<=R) { xx[len++]=p[j].x; } } sort(xx,xx+len); xx[len++]=INF; int temp=0; for(int j=0;j<len-1;j++) { while(xx[temp]<=xx[j]+r) temp++; ans=max(temp-j,ans); } } printf("%d\n",ans); } return 0;}
- HDU 4007:Dave (枚举)
- hdu 4007 枚举 Dave
- HDU 4007 Dave 枚举
- HDU 4007 Dave (暴力枚举)
- hdu 4007 暴力枚举 Dave
- HDU--4007[Dave] O(N^2)枚举
- HDU 4007 Dave (基本算法-水题)
- hdu 4007 Dave
- hdu 4007 Dave
- hdu 4007 Dave
- HDU 4007 Dave
- hdu 4007 Dave
- HDU 4007 Dave
- HDU 4007 Dave
- HDU 4007 Dave 线段树
- hdu 4007 Dave(线段树+离散化+扫描线)
- HDU 4007 Dave(双扫描线+技巧暴力)
- hdu 4007 Dave 求矩形圈点最大值
- 元类
- MySQL数据类型
- windows下virtualenv使用多版本python
- springmvc和Struts2
- 【React Native】RN错误更新中……
- HDU 4007:Dave (枚举)
- java中int转String
- idea的实用功能
- L2-022. 重排链表
- Javascript模块化编程
- 项目管理工具maven(1)
- Effective c++ 学习笔记 1
- Java HashSet练习
- Java之集合类(2)