HDOJ 4007 Dave【最大覆盖集】
2014-04-01 16:57
134 查看
Dave
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 2768 Accepted Submission(s): 926
[align=left]Problem Description[/align]
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).
[align=left]Input[/align]
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.
[align=left]Output[/align]
Output the largest number of people in a square with the length of R.
[align=left]Sample Input[/align]
3 2
1 1
2 2
3 3
[align=left]Sample Output[/align]
3
Hint
If two people stand in one place, they are embracing.
[align=left]Source[/align]
The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest
AC代码:
#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> using namespace std; struct node{ int x,y; }a[1010],b[1010]; bool cmp(node a,node b){ return a.x < b.x; } int main(){ int y[1010]; int n,r,i,j,Max; int x1,x2,y1,y2; int x_min,x_max,y_min,y_max; while(EOF != scanf("%d%d",&n,&r)){ Max = -1; x_min = y_min = 999999999; x_max = y_max = -1; for(i=0;i<n;i++){ scanf("%d%d",&a[i].x,&a[i].y); if(a[i].x < x_min) x_min = a[i].x; if(a[i].x > x_max) x_max = a[i].x; if(a[i].y < y_min) y_min = a[i].y; if(a[i].y > y_max) y_max = a[i].y; b[i] = a[i]; } if(y_max-y_min <= r && x_max-x_min <= r){ printf("%d\n",n); continue; } sort(a,a+n,cmp); int Max = 0; for(int i=0;i<n;i++){ int k = 0; for(int j = i;a[j].x <= a[i].x + r && j < n;j++)//对x值不大于a[j].x + r遍历 y[k++] = a[j].y;//将比a[i] 的 x值小的a[j]点 的y值加入y数组 sort(y,y+k);//对y数组排序 int flag = 0,temp = 0; for(int j = 0;j < k && temp < k ;j++){//对y数组中所有元素遍历 while(y[temp] - y[j] <= r && temp < k) temp++; if(temp -j > Max) Max= temp - j; } } printf("%d\n",Max); } return 0; }
相关文章推荐
- hdu 4007 Dave 求矩形圈点最大值
- HDOJ 2236 - 无题II 暴力+二分图最大匹配判断
- hdoj 过山车 2063 (二分图最大匹配)
- hdoj2054又见GCD(GCD最大公约数)
- hdu 4007 Dave (2011年大连ACM网络赛)
- HDOJ 4309 - Seikimatsu Occult Tonneru 枚举,构图,最大流..
- hdoj1754 I Hate It【线段树区间最大值维护+单点更新】
- 【HDOJ 3729】 I'm Telling the Truth (二分图最大匹配)
- HDOJ 题目1281 棋盘游戏(二分图最大匹配,删边)
- HDOJ1231 最大连续子序列
- hdoj 3376 Matrix Again and hdoj 2686 Matrix 【最大费用最大流】
- hdoj 3338 Kakuro Extension 【经典最大流+输出流量】
- hdoj 3395 Special Fish 【最大费用流】
- HDOJ题目3829Cat VS Dog(二分图,最大独立集)
- HDOJ 1532 Drainage Ditches(最大流)
- hdoj 3996 Gold Mine 【最小割 之 最大权闭合图】
- hdoj 4786 Fibonacci Tree 【最小生成树&&最大生成树】
- HDOJ 1087最大递增子序列和
- hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】
- HDOJ(HDU) 2107 Founding of HDU(找最大值)