Dave

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 2768    Accepted Submission(s): 926

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

Hint

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

 
Source
 
AC代码:
 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
struct node{
int x,y;
}a[],b[];
bool cmp(node a,node b){
return a.x < b.x;
}
int main(){
int y[];
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 = -;
x_min = y_min = ;
x_max = y_max = -;
for(i=;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 = ;
for(int i=;i<n;i++){
int k = ;
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 = ,temp = ;
for(int j = ;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 ;
}

HDOJ 4007 Dave【最大覆盖集】的更多相关文章

  1. POJ2125 Destroying The Graph(二分图最小点权覆盖集)

    最小点权覆盖就是,对于有点权的有向图,选出权值和最少的点的集合覆盖所有的边. 解二分图最小点权覆盖集可以用最小割: vs-X-Y-vt这样连边,vs和X部点的连边容量为X部点的权值,Y部和vt连边容量 ...

  2. POJ2125 Destroying The Graph (最小点权覆盖集)(网络流最小割)

                                                          Destroying The Graph Time Limit: 2000MS   Memo ...

  3. POJ 2125 Destroying The Graph (二分图最小点权覆盖集+输出最小割方案)

    题意 有一个图, 两种操作,一种是删除某点的所有出边,一种是删除某点的所有入边,各个点的不同操作分别有一个花费,现在我们想把这个图的边都删除掉,需要的最小花费是多少. 思路 很明显的二分图最小点权覆盖 ...

  4. HDU 1569 - 方格取数(2) - [最大点权独立集与最小点权覆盖集]

    嗯,这是关于最大点权独立集与最小点权覆盖集的姿势,很简单对吧,然后开始看题. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1569 Time Limi ...

  5. 最小点权覆盖集&最大点权独立集

    最小点权覆盖集 二分图最小点权覆盖集解决的是这样一个问题: 在二分图中,对于每条边,两个端点至少选一个,求所选取的点最小权值和. 方法: 1.先对图二分染色,对于每条边两端点的颜色不同 2.然后建立源 ...

  6. hdu1569 方格取数(2) 最大点权独立集=总权和-最小点权覆盖集 (最小点权覆盖集=最小割=最大流)

    /** 转自:http://blog.csdn.net/u011498819/article/details/20772147 题目:hdu1569 方格取数(2) 链接:https://vjudge ...

  7. POJ 2125 最小点权覆盖集(输出方案)

    题意:给一个图(有自回路,重边),要去掉所有边,规则:对某个点,可以有2种操作:去掉进入该点 的所有边,也可以去掉出该点所有边,(第一种代价为w+,第二种代价为w-).求最小代价去除所有边. 己思:点 ...

  8. hdu 4007 Dave(线性探查+枚举)

    Problem Description Recently, Dave is boring, so he often walks around. He finds that some places ar ...

  9. HDU 4007 Dave(离散化)

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

随机推荐

  1. SQL中distinct的用法(转)

    原文:http://www.cnblogs.com/rainman/archive/2013/05/03/3058451.html 在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出 ...

  2. java的大数类

    java中的大数类,真的很方便,不用自己再写计算的函数,先写一个简单的例子,以后再补充 注意大数初始化的时候,参数十字符型的,如果传进去的变量十一个数字,需要加上一个空字符即:+"" ...

  3. LNMP下基于端口的虚拟主机配置

    1.在/usr/local/nginx/conf/nginx.conf文件的的最后一个"}"前加上 include vhost/*.conf; 2.在/usr/local/ngin ...

  4. [LeetCode]题解(python):044-Wildcard Matching

    题目来源: https://leetcode.com/problems/wildcard-matching/ 题意分析: 定义两个新字符规则,'?'代表任意一个字符,’*‘代表任意长度的任意字符.输入 ...

  5. C陷阱与缺陷(二)

    第二章 语法陷阱 2.1 理解函数声明 (*(void(*)())0)();任何C变量的声明都由两部分组成:类型以及一组类似表达式的声明符.一旦我们知道了如何声明一个给定类型的变量,那么该类型的类型转 ...

  6. QRadionButton 圆点样式

    QRadioButton::indicator {    width: 13px;    height: 13px;} QRadioButton::indicator::unchecked {     ...

  7. KbmMW两种查询结果集通讯方式

    KbmMW本身可以用QueryService的方式进行远程数据查询,但是SmpileService同样具有很强的扩展性可以实现数据查询,下面展示两种基于SmpileService的远程数据查询方法,其 ...

  8. perl 安装Net::ZooKeeper

    <pre name="code" class="python"><pre name="code" class=" ...

  9. python概要

    python与r语言接口Rpy,统计 科学计算,数值拟合:numpy,scipy 可视化2d:matplotlib,Pylab 可视化3d:mayaviz 复杂网络:networkx 交互终端: bs ...

  10. 基于visual Studio2013解决C语言竞赛题之0405阶乘求和

      题目 解决代码及点评 这道题和上一道题类似,第n个累加项 = n-1累加项的n倍 由于有这个规律,我们可以用一个for循环实现 但是例子代码并没有这么做,大家可以回去修改下代码,使得代码更 ...