HDOJ 4007 Dave【最大覆盖集】
Dave
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 2768 Accepted Submission(s): 926
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 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.
1 1
2 2
3 3
If two people stand in one place, they are embracing.
#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【最大覆盖集】的更多相关文章
- POJ2125 Destroying The Graph(二分图最小点权覆盖集)
最小点权覆盖就是,对于有点权的有向图,选出权值和最少的点的集合覆盖所有的边. 解二分图最小点权覆盖集可以用最小割: vs-X-Y-vt这样连边,vs和X部点的连边容量为X部点的权值,Y部和vt连边容量 ...
- POJ2125 Destroying The Graph (最小点权覆盖集)(网络流最小割)
Destroying The Graph Time Limit: 2000MS Memo ...
- POJ 2125 Destroying The Graph (二分图最小点权覆盖集+输出最小割方案)
题意 有一个图, 两种操作,一种是删除某点的所有出边,一种是删除某点的所有入边,各个点的不同操作分别有一个花费,现在我们想把这个图的边都删除掉,需要的最小花费是多少. 思路 很明显的二分图最小点权覆盖 ...
- HDU 1569 - 方格取数(2) - [最大点权独立集与最小点权覆盖集]
嗯,这是关于最大点权独立集与最小点权覆盖集的姿势,很简单对吧,然后开始看题. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1569 Time Limi ...
- 最小点权覆盖集&最大点权独立集
最小点权覆盖集 二分图最小点权覆盖集解决的是这样一个问题: 在二分图中,对于每条边,两个端点至少选一个,求所选取的点最小权值和. 方法: 1.先对图二分染色,对于每条边两端点的颜色不同 2.然后建立源 ...
- hdu1569 方格取数(2) 最大点权独立集=总权和-最小点权覆盖集 (最小点权覆盖集=最小割=最大流)
/** 转自:http://blog.csdn.net/u011498819/article/details/20772147 题目:hdu1569 方格取数(2) 链接:https://vjudge ...
- POJ 2125 最小点权覆盖集(输出方案)
题意:给一个图(有自回路,重边),要去掉所有边,规则:对某个点,可以有2种操作:去掉进入该点 的所有边,也可以去掉出该点所有边,(第一种代价为w+,第二种代价为w-).求最小代价去除所有边. 己思:点 ...
- hdu 4007 Dave(线性探查+枚举)
Problem Description Recently, Dave is boring, so he often walks around. He finds that some places ar ...
- HDU 4007 Dave(离散化)
Dave Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submis ...
随机推荐
- [小知识点]IE6下不支持:hover的解决方法
在网上百度到的解决办法,感觉不错,和大家分享一下. 在CSS样式里加一句代码"body{behavior:url("文件夹/csshover.htc");}"即 ...
- 「OC」@property @synthesize和id
一.@property @synthesize关键字 这两个关键字是编译器特性,让Xcode可以自动生成getter和setter. (一)@property 关键字 @property 关键字可以自 ...
- Java 操作mongodb
package cn.test.db; import java.io.File; import java.io.IOException; import java.net.UnknownHostExce ...
- QQ对话代码
<li> <strong class="QQ">客服QQ</strong> <span> <a href="mqqw ...
- (Problem 29)Distinct powers
Consider all integer combinations ofabfor 2a5 and 2b5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, ...
- c 占位符
%d, %i,代表整数,%f-浮点,%s,字符串,%c,char. %p 指针,%fL 长log,%e科学计数,%g 小数或科学计数. C语言中的格式占位符: %a,%A 读入一个浮点值(仅C9 ...
- 转:按需加载html 图片 css js
按需加载是前端性能优化中的一项重要措施,按需加载是如何定义的呢?顾名思义,指的是当用户触发了动作时才加载对应的功能.触发的动作,是要看具体的业务场景而言,包括但不限于以下几个情况:鼠标点击.输入文字. ...
- cygwin中vim的使用方法
vim类似Windows中的记事本,功能非常强大. vim的使用技巧 1.vim text.txt text存在则打开,不存在则类似新建一个叫text的txt文件 2.退出 按esc切换到命令模式,然 ...
- 【Eclipse】WebServiceExplorer
1.点击以下按钮启动Eclipse Web Service Explorer 2.点击页面右上角的WSDL PAGE按钮 3.点击页面左上角WSDL MAIN-->输入WSDL地址-->选 ...
- 畅通工程续(Dijkstra算法)
对Dijkstra算法不是很熟悉,写一下思路,希望通过写博客加深理解 Description 某省自从实行了很多年的畅通工程计划后,终于修建了很多路.不过路多了也不好,每次要从一个城镇到另一个城镇时, ...