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 ...
随机推荐
- 使用LiveWriter发布Orchard博客
我们可以Windows Live Writer来发布Orchard博客 在Dashboard–> Modules菜单找到 Remote Blog Publishing 模块.点击 Enable ...
- 界面调试工具Reveal的使用介绍
Reveal 注: 此处介绍Reveal,其中大部分内容来自于唐巧的<iOS开发进阶>一书,以此说明. 如何使用Reveal进行模拟器调试,只需进行以下三个步骤即可. 1. 创建.lldb ...
- iOS开发 点击跳转到App Store 或者 点击按钮去评价
//跳转到应用页面 NSString *str = [NSString stringWithFormat:@"http://itunes.apple.com/us/app/id%d" ...
- URAL 1225 Flags
题目:click here #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int n; ll ...
- sdl2-2.04 读取位图并显示
// sdl2_win32.cpp : Defines the entry point for the console application.//// 假定SDL的库文件和头文件和VC的工程文件在一 ...
- vagrant 入门1
1. Vagrant功能: Vagrant usesOracle's VirtualBox to build configurable, lightweight, and portable ...
- 谈谈我的iOS学习及分享
iOS可以说是最近几年比较热门和高速发展一个系统,因此iOS开发也变得火热.越来越多的程序员都转向了iOS开发,每个人的学习方法都不同,分享下我的学习经历和见解吧.我之前学习过C++和Qt,Java也 ...
- 转:前端冷知识(~~some fun , some useful)
前端不为人知的一面——前端冷知识集锦 前端已经被玩儿坏了!像console.log()可以向控制台输出图片等炫酷的玩意已经不是什么新闻了,像用||操作符给变量赋默认值也是人尽皆知的旧闻了,今天看到Qu ...
- Android studio dabao
首先肯定是配置gradle,百度一下就知道了,我的是mac下配置的,sudo vim ~/.bash_profile ,然后设置环境变量 GRADE_HOME=/Users/Admin/gradle; ...
- X-UA-Compatible IE 浏览器默认文档模式设置
制作网页的时候,IE8浏览器浏览页面的时候,有时候文档模式默认是IE7,导致IE8兼容性不是非常好.出现IE7应该出现的模式. 解决的方法例如以下: 在X-UA-Compatible中可用的方法有: ...