千里莺啼绿映红(10pts)
查看原帖
千里莺啼绿映红(10pts)
565450
__K2FeO4楼主2022/11/11 22:56

AC on #6

#include<bits/stdc++.h>
using namespace std;
const int N=228941;
typedef long long ll;
int n,m,nex[N],pre[N],ans[N];
bool u[N];
struct node{
	ll x,y,z,id;
	ll sql(){
		return x*x+y*y;
	}
}a[N];
bool clen(node p,node q){
	return p.sql()<q.sql();
}
bool cmp(node p,node q){
	if(p.x==0){
		if(p.y==0)return true;
		else if(p.y>0){
			if(q.x)return true;
			else if(q.y<0)return true;
			else return clen(p,q);
		}
		else{
			if(q.x<0)return true;
			if(q.x>0)return false;
			if(q.y>0)return false;
			else return clen(p,q);
		}
	}
	else if(q.x==0){
		return !cmp(q,p);
	}
	else{
		if(p.x>0&&q.x<0)return true;
		else if(p.x<0&&q.x>0)return false;
		else{
			ll v=p.y*q.x-p.x*q.y;
			if(v==0)return clen(p,q);
			return v>0;
		}
	}
}
bool isl(node p,node q){
	if(p.x==0&&q.x==0)return p.y*q.y>=0;
	if(p.x*q.x<0)return false;
	return p.y*q.x==p.x*q.y;
}
//double deg(double x){return x/pi*180;}
//double rad(double x){return x*pi/180;}
signed main(){
	//double x,y;
	//cin>>x>>y;
	//cout<<deg(atan(x/y))<<endl;
	memset(ans,-1,sizeof(ans));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].z),a[i].id=i;
	sort(a+1,a+n+1,cmp);
	//for(int i=1;i<=n;i++)
	//printf("%lld %lld %lld\n",a[i].x,a[i].y,a[i].z);
	for(int i=1;i<=n;i++)
	nex[i]=i+1,pre[i]=i-1;
	nex[n]=1,pre[1]=n;
	int cnt=0,now=1;
	u[0]=1;
	for(int i=1;cnt<n;i=nex[i]){
		//printf("%d\n",i);
		if(a[i].sql()<=m*m){
			ans[a[i].id]=now;
			m+=a[i].z;
			cnt++;
			nex[pre[i]]=nex[i];
			pre[nex[i]]=pre[i];
		}
		if(!isl(a[i],a[nex[i]]))now=cnt+1;
		if(u[cnt]==1)break;
		if(i>=nex[i])u[cnt]=1;
	}
	for(int i=1;i<=n;i++)
	printf("%d ",ans[i]);
	return 0;
}
2022/11/11 22:56
加载中...