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. BFG

    "/"应用程序中的服务器错误. 配置错误 说明: 在处理向该请求提供服务所需的配置文件时出错.请检查下面的特定错误详细信息并适当地修改配置文件. 分析器错误消息: 提供程序集合中不 ...

  2. 由命名空间函数而引发思考--js中的对象赋值问题

    最近没有编码任务,作为一个才毕业的小辣鸡,给的任务就是看一下公司的新系统,熟悉怎么用哪些地方是干什么的. 下午喝了两杯水,感觉有点浪.然后就开始看了下代码.发现有一个函数是这样子的. var TX = ...

  3. java反射机制入门02

    Field对象的机制与实现 1.Field对象概述 1)Java.lang.reflect.Field类,是用于表示类中.接口中属性对象的类. 2)可以操作类中私有,以及公有等全部属性和属性的信息. ...

  4. C++对象的销毁

  5. Longest Palindromic Substring - 一题多解

    题意是寻找一个字符串的最大回文字串,最简单的是n3方的算法,由于字符串最大长度为1000,所以这个方法很危险而且不科学. 紧接着想到的是一个n方的算法:回文子串是从中间向两边产生的,那么对于每个字符考 ...

  6. 通过代码...CGRectmake 创建的控件如何自适应屏幕。

    [[UIScreen mainScreen] bounds].size.width [[UIScreen mainScreen] bounds].size.height 得到屏幕的宽高,然后将变量写入 ...

  7. Java疯狂讲义

  8. spring 事务 笔记3.1

    Spring事务 以前的事务都是编程式事务,需要开启和关闭,然后程序写在这里面 spring,声明式事务 Spring事务隔离级别 DEFAULT 使用数据库默认隔离级别 READ_UNCOMMITT ...

  9. [置顶] IT屌丝的离职申请

          各位好,很遗憾在如此关键的时刻和大家说告别.我为金三也付出了近一年的心血,几乎没怎么休过令人舒心的周末,熬了多少夜更不用说,如此的离开,请相信我也非常心痛.       尽管直到现在我的水 ...

  10. os.path.exists(path) 和 os.path.lexists(path) 的区别

    使用os.path.exists()方法可以直接判断文件是否存在.代码如下:>>> import os>>> os.path.exists(r'C:\1.TXT') ...