您的位置:首页 > 其它

4007 Dave(The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest)

2017-07-06 19:41 573 查看

Dave

Problem Description

Recently, Dave is boring, so he often walks around. He finds that some places are too crowded, for example, the ground. He couldn’t help to think of the disasters happening recently. Crowded place is not safe. He knows there are N (1<=N<=1000) people on the ground. Now he wants to know how many people will be in a square with the length of R (1<=R<=1000000000). (Including boundary).

Input

The input contains several cases. For each case there are two positive integers N and R, and then N lines follow. Each gives the (x, y) (1<=x, y<=1000000000) coordinates of people.

Output

Output the largest number of people in a square with the length of R.

Sample Input

3 2

1 1

2 2

3 3

一共只有1000个点,先依次将其中的一个点作为标准点与其他点比较,如果两个点的范围在r之间就放入x数组中,然后再比较x数组中有几个点的范围在r之间,取最大值就行

#include<bits/stdc++.h>
using namespace std;
using LL =int64_t;

struct Node {
LL x,y;
}E[1005];
LL x[1005],y[1005];

int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
LL n,r;
while(cin>>n>>r) {
for(int i=0;i<n;i++) cin>>E[i].x>>E[i].y;
for(int i=0;i<n;i++) y[i]=E[i].y;
sort(y,y+n);
int cnt=0,temp;
for(int i=0;i<n;i++) {
temp=0;
for(int j=0;j<n;j++)
if(E[j].y<=y[i]+r&&E[j].y>=y[i]) x[temp++]=E[j].x;
sort(x,x+temp);
int ans=0;
x[temp++]=2e9;
for(int j=0;j<temp-1;j++) {
while(x[ans]<=x[j]+r) ans++;
cnt=max(cnt,ans-j);
}
}
cout<<cnt<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐