全RE爆0求助
查看原帖
全RE爆0求助
1084912
nzy0211楼主2024/10/2 07:54
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,fa[N],vis[N],bj[N],ans[N],cnt1,cnt2;
char op;
struct node{
	int x,y,id;
}a[N],b[N]; 
bool cmp1(const node &a,const node &b){
	return a.y<b.y;
}
bool cmp2(const node &a,const node &b){
	return a.x<b.x;
}
int find(int x){
	if(fa[x]==x)
		return x;
	return fa[x]=find(fa[x]);
}
int merge(int x,int y){
	int nx=find(x),ny=find(y);
	if(nx!=ny){
		fa[nx]=ny;
		ans[ny]=ans[nx]+1;
	}
}
int main(){
	cin>>n;
	for(int i=1,x,y;i<=n;i++){
		cin>>op>>x>>y;
		if(op=='E')
			a[++cnt1].x=x,a[cnt1].y=y,a[cnt1].id=i;
		else
			b[++cnt2].x=x,b[cnt2].y=y,b[cnt2].id=i;
		fa[i]=i;
	}
	sort(a+1,a+1+cnt1,cmp1);
	sort(b+1,b+1+cnt2,cmp2);
	for(int i=1;i<=cnt1;i++){
		for(int j=1;j<=cnt2;j++){
			if(vis[j]||a[i].x>b[j].x||a[i].y<b[j].y||a[i].x+a[i].y==b[j].x+b[j].y)
				continue;
			if(a[i].x+a[i].y<b[j].x+b[j].y){
				bj[a[i].id]=1;
				merge(a[i].id,b[j].id);
				break;
			}else{
				bj[b[j].id]=1;
				merge(b[j].id,a[i].id);
				vis[j]=1;
			}
		}
	}
	for(int i=1;i<=n;i++)
		cout<<ans[i]<<'\n';
	return 0;
}/*
6
E 3 5
N 5 3
E 4 6
E 10 4
N 11 1
E 9 2
answer:
0
0
1
2
1
0
*/

2024/10/2 07:54
加载中...