参考博客http://www.cppblog.com/aswmtjdsj/archive/2011/09/04/155049.aspx

维护4根双扫描线,左右和上下。暴力枚举,复杂度O(n^2).

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 1001;
struct Point{
int x, y;
};
int n, R;
Point vx[MAXN], vy[MAXN];
bool cmpx(Point a, Point b){
return a.x < b.x;
}
bool cmpy(Point a, Point b){
return a.y < b.y;
}
int getMAX(){
int l, r, u,i,j,t=0;;
int ans = 0;
for (i = 0; i < n; i++){
l = vx[i].x; //左边线
while (t < n&&vx[t].x - l <= R)t++;
t--;
r = vx[t].x;
int s = 0,temp=0;
for (j = 0; j < n; j++){
u = vy[j].y;
while (s < n&&vy[s].y - u <= R){
if (vy[s].x <= r&&vy[s].x>=l)
temp++;
s++;
}
ans = max(ans, temp);
//为下一次做准备
if (vy[j].x <= r&&vy[j].x >= l)
temp--;
}
}
return ans;
}
int main(){
while (~scanf("%d%d", &n, &R)){
for (int i = 0; i < n; i++){
scanf("%d%d", &vx[i].x, &vx[i].y);
vy[i] = vx[i];
}
sort(vx, vx + n, cmpx);
sort(vy, vy + n, cmpy);
int ans = getMAX();
printf("%d\n", ans);
}
return 0;
}

  

hdu4001的更多相关文章

随机推荐

  1. string 与 byte[] 互转时的注意事项

    1.string 转 byte[] //为UTF8编码 byte[] midbytes=isoString.getBytes("UTF8"); //为ISO-8859-1编码,其中 ...

  2. Rational Rose 使用技巧

    1.浏览区 2.菜单项 其中Format选项中: 决定各项是否显示,也可以通过右击-option选择 3.常用快捷键: F1:任何时候都可以按F1获得相关帮助,把鼠标放在某条菜单上按F1可以获得这条菜 ...

  3. swagger-ui enum select

    swagger-ui enum select Array[string] https://dejanstojanovic.net/aspnet/2018/march/displaying-multip ...

  4. 【bzoj2212】[Poi2011]Tree Rotations 权值线段树合并

    原文地址:http://www.cnblogs.com/GXZlegend/p/6826614.html 题目描述 Byteasar the gardener is growing a rare tr ...

  5. JZOJ 5280 膜法师

    好啰嗦......还好作者给了一句话题意,不然光看题就很耗费时间. 样例输入: 1 6 3 1 78 69 55 102 233 666 样例输出: 1 2 3 4 5 6 11  数据范围: 思路: ...

  6. POJ 3041 Asteroids | 匈牙利算法模板

    emmmmm 让你敲个匈牙利 #include<cstdio> #include<algorithm> #include<cstring> #define N 51 ...

  7. CSS实现放大镜/狙击镜效果

    图片放大,这是一个比较容易的效果了.当然,今天说的可不是简简单单的在一个框里放大,而是一个圆.就像放大镜或是狙击镜那样,只有圆圈里的放大,圈外的当然还是原来的图片.这是不是很不可思议? 当然不是.做过 ...

  8. 用$("...").attr("checked", true)设置勾选无效的原因

    如下图所示,本来想要实现如下图所示的功能,于是我本来是使用$("...").attr("checked", true/false)来实现该功能,但是第一次点击时 ...

  9. 启动、停止、删除Windows服务

    启动: @echo.服务启动...... @echo off @sc create Service_SMS binPath= "D:\公司制度等文件\项目\河北劳动力市场检测系统\Windo ...

  10. getprop 获取android系统属性

    Android属性系统 property_get/property_set  (很透彻)http://www.blogjava.net/MEYE/articles/359773.html getpro ...