HDU4007 Dave [杂题]

  以为是什么复杂的几何题,结果边长是平行于坐标轴的,一下子就变成大水题了。找了半天也没发现题目哪写了边长平行于坐标轴。。。

  数据范围小,n次枚举*nlogn排序,暴力枚举就可以过。

#include <stdio.h>
#include <string.h>
#include <algorithm>
#define MAXN 1005

int n,r;
struct pnt{
    int x,y;
}p[MAXN],p2[MAXN];
bool cmpx(const pnt& p1,const pnt& p2){
    return p1.x<p2.x;
}
bool cmpy(const pnt& p1,const pnt& p2){
    return p1.y<p2.y;
}
int main(){
    while(scanf("%d%d",&n,&r)!=EOF){
        for(int i=0;i<n;i++)scanf("%d%d",&p[i].x,&p[i].y);
        std::sort(p,p+n,cmpx);
        int ans=0;
        for(int i=0;i<n;i++){
            if(i>0&&p[i].x==p[i-1].x)continue;
            int ps=0;
            for(int j=0;j<n;j++)
                if(p[j].x>=p[i].x&&p[j].x<=p[i].x+r)p2[ps++]=p[j];
            std::sort(p2,p2+ps,cmpy);
            for(int j=0,rt=0,tmp=0;j<ps;j++,tmp--){
                while(rt<ps&&p2[rt].y-p2[j].y<=r)rt++,tmp++;
                if(tmp>ans)ans=tmp;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
posted @ 2012-08-27 21:53  Burn_E  阅读(121)  评论(0)    收藏  举报