hdu 4007 暴力or线段树 ***

时间:2023-03-09 05:40:29
hdu 4007 暴力or线段树 ***

尼玛,INF不能定义太大,找标程对拍了好久

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=2e9;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt;
struct Node
{
int x,y;
void in()
{
scanf("%d%d",&x,&y);
}
}node[MAXN];
bool cmp(Node a,Node b)
{
return a.y<b.y;
}
int ans[MAXN],R,tot;
int main()
{
int i,j,k;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
while(scanf("%d%d",&n,&R)!=EOF)
{
for(i=;i<n;i++)
{
scanf("%d%d",&node[i].x,&node[i].y);
}
sort(node,node+n,cmp);
int MAX=,e;
for(i=;i<n;i++)
{
tot=;
for(j=;j<n;j++)
{
if(node[j].y>=node[i].y&&node[j].y<=node[i].y+R)
ans[tot++]=node[j].x;
}
sort(ans,ans+tot);
ans[tot++]=INF;
e=;
for(j=;j<tot-;j++)
{
while(ans[e]<=ans[j]+R) e++;
MAX=max(MAX,(e-j));
}
}
printf("%d\n",MAX);
}
}