网上的题解直接用随机过的,
自己用模拟就模拟三个向量的和并就模拟不出来。。
以后再回头看看
#include<bits/stdc++.h> #include<cmath> using namespace std; const double esp = 1e-8; const int maxn = 1e5+10; const double C = 180.0/acos(-1.0); struct Vector{ double x,y,len,angle; int k,id; }p[maxn]; int cmp(Vector a,Vector b){return a.len>b.len;} int n; void reverse(Vector &v){ v.k*=-1;v.x*=-1;v.y*=-1; v.angle=atan2(v.y,v.x)*C; if(v.angle<0)v.angle+=360; } void add(Vector &a, Vector &b){ a.x+=b.x;a.y+=b.y; a.len=sqrt(a.x*a.x+a.y*a.y); a.angle=atan2(a.y,a.x)*C; if(a.angle<0)a.angle+=360; } void Merge(Vector &a,Vector &b,Vector &c){//把c向量加到a向量或者b向量里 double r1=a.angle,r2=c.angle; if(r1>r2)swap(r1,r2); double A=min(fabs(r2-r1),fabs(r1-r2+360)); if(A<=180 && A>=120){//形成钝角 add(a,c);return; } else if(A<=60){//形成锐角 reverse(c); add(a,c); return; } r1=b.angle,r2=c.angle; if(r1>r2)swap(r1,r2); double B=min(fabs(r2-r1),fabs(r1-r2+360)); if(B<=180 && B>=120){ add(b,c);return; } else if(B<=60){//形成锐角 reverse(c); add(b,c); return; } Vector tmp=b;b=c;c=tmp; r1=a.angle,r2=c.angle; if(r1>r2)swap(r1,r2); A=min(fabs(r2-r1),fabs(r1-r2+360)); if(A<=180 && A>=120){//形成钝角 add(a,c);return; } else if(A<=60){//形成锐角 reverse(c); add(a,c); return; } } int main(){ cin>>n; for(int i=1;i<=n;i++){ scanf("%lf%lf",&p[i].x,&p[i].y); p[i].len=sqrt(p[i].x*p[i].x+p[i].y*p[i].y); p[i].angle=atan2(p[i].y,p[i].x)*C; if(p[i].angle<0) p[i].angle+=360; p[i].id=i;p[i].k=1; } sort(p+1,p+1+n,cmp); Vector &a=p[1], &b=p[2]; for(int i=3;i<=n;i++){ Vector &c=p[i]; Merge(a,b,c); if((a.x+b.x)*(a.x+b.x)>=2.25*1e12) cout<<i<<" NO"; } /* cout<<a.x<<" "<<a.y<<' '; cout<<b.x<<" "<<b.y<<' ';*/ int ans[maxn]={}; for(int i=1;i<=n;i++) ans[p[i].id]=p[i].k; for(int i=1;i<=n;i++)cout<<ans[i]<<" "; }