首页 技术 正文
技术 2022年11月21日
0 收藏 704 点赞 3,244 浏览 1351 个字

参考:http://hzwer.com/4361.html

坐标开long long,inf开大点

先曼哈顿转切比雪夫(x+y,x-y),距离就变成了max(x’,y’);

先按x排序,维护两个指针,指针内区间的x差总是<=c;

用一个multiset维护指针内元素,按y排序,每次加的时候找这个点y的前驱后继,判断是否符合y的差<=c(x已经通过左指针右移eraser完成了),是则加入并查集,像生成树那样的做法;

然后统计一下并查集的根个数和maxsize即可

转切比雪夫是重点!

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
const int N=100005;
const long long inf=1e15;
int n,m,f[N],c[N],con,mx;
struct qwe
{
long long x,y;
int id;
qwe(long long X=0,long long Y=0,int ID=0)
{
x=X,y=Y,id=ID;
}
bool operator < (const qwe &a) const
{
return y<a.y;
}
}a[N];
multiset<qwe>s;
bool cmp(const qwe &a,const qwe &b)
{
return a.x<b.x;
}
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
inline int zhao(int x)
{
return x==f[x]?x:f[x]=zhao(f[x]);
}
void hb(int x,int y)
{
int fx=zhao(x),fy=zhao(y);
if(fx!=fy)
f[fx]=fy;
}
int main()
{
n=read(),m=read();
for(int i=1;i<=n;i++)
{
int x=read(),y=read();
a[i]=qwe(x+y,x-y,i);f[i]=i;
}
sort(a+1,a+1+n,cmp);
s.insert(qwe(0,inf,0));
s.insert(qwe(0,-inf,0));
s.insert(a[1]);
int w=1;
for(int i=2;i<=n;i++)
{
while(a[i].x-a[w].x>m)
s.erase(s.find(a[w++]));
multiset<qwe>::iterator it=s.lower_bound(a[i]);
qwe r=*it,l=*--it;
if(a[i].y-l.y<=m)
hb(a[i].id,l.id);
if(r.y-a[i].y<=m)
hb(a[i].id,r.id);
s.insert(a[i]);
}
for(int i=1;i<=n;i++)
c[zhao(i)]++;
for(int i=1;i<=n;i++)
if(c[i]>0)
mx=max(mx,c[i]),con++;
printf("%d %d\n",con,mx);
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919