HDU4007 Dave [杂题]
生活随笔
收集整理的這篇文章主要介紹了
HDU4007 Dave [杂题]
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
以為是什么復雜的幾何題,結果邊長是平行于坐標軸的,一下子就變成大水題了。找了半天也沒發現題目哪寫了邊長平行于坐標軸。。。
數據范圍小,n次枚舉*nlogn排序,暴力枚舉就可以過。
#include <stdio.h> #include <string.h> #include <algorithm> #define MAXN 1005int 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; }轉載于:https://www.cnblogs.com/swm8023/archive/2012/08/27/2659220.html
總結
以上是生活随笔為你收集整理的HDU4007 Dave [杂题]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 屌丝逆袭高富帅之JAVA之路
- 下一篇: 乳腺结节治疗方法有哪些(颚口线虫病的治疗