您的位置:首页 > 其它

hdu 4007 Dave

2016-07-04 07:48 211 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4007

题意:给n个点的坐标,给一个边长为r的正方形,求正方形内最多有多少点。



这题给的正方形实际上是平行于x轴的,题意没表达清楚。所以用暴力就可以过,排序,平行x轴,排序,然后再平移y。

#include<bits/stdc++.h>
#define N 1100
using namespace std;

struct node
{
int x,y;
}p
;
int n,r,t
;

bool cmp(node a,node b)
{
return a.x<b.x;
}

int main()
{
while(~scanf("%d%d",&n,&r))
{
for(int i=0;i<n;i++) scanf("%d%d",&p[i].x,&p[i].y);
sort(p,p+n,cmp);
int ans=0;
for(int i=0;i<n;i++)
{
int x=p[i].x+r;
int m=0;
for(int j=i;p[j].x<=x&&j<n;j++) t[m++]=p[j].y;
sort(t,t+m);
int cnt=0,sum=0;
for(int j=0;j<m;j++)
{
int y=t[j]+r;
while(cnt<m&&t[cnt]<=y) cnt++;
sum=max(sum,cnt-j);
}
ans=max(ans,sum);
}
cout<<ans<<endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: