zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    自动化运维
    rabbitmq常见问题
    常见的排序算法
    rabbitmq
    redis-其他应用
    redis之缓存穿透、雪崩、击穿
    redis-cluster(集群)
    redis -sentinel(哨兵)
    redis持久化
    redis简介
  • 原文地址:https://www.cnblogs.com/swm8023/p/2659220.html
Copyright © 2011-2022 走看看