标签:半径 content div can 抽象 int long ++i desc
#include<cstdio> #include<cmath> typedef long double ld; const ld _0=1e-7; ld x[2007],y[2007],r[2007]; void get(int id,ld X,ld&a,ld&b){ X-=x[id]; X=std::sqrt(r[id]*r[id]-X*X); a=y[id]-X-_0; b=y[id]+X+_0; } ld dis(int a,int b){ ld X=x[a]-x[b],Y=y[a]-y[b]; return sqrt(X*X+Y*Y); } ld cal(int a,int b){ return x[a]+(x[b]-x[a])*r[a]/dis(a,b); } bool chk(int n){ ld L=x[1]-r[1],R=x[1]+r[1],M; for(int i=2;i<=n;++i){ if(x[i]-r[i]<L)L=x[i]-r[i]; if(x[i]+r[i]>R)R=x[i]+r[i]; } while(1){ M=(L+R)/2; bool dl=0,dr=0; for(int i=1;i<=n;++i){ if(x[i]+r[i]<M)dl=1; if(x[i]-r[i]>M)dr=1; } if(dl){ if(dr)return 0; R=M; }else if(dr)L=M; else{ ld y1,y2,a1,a2; get(1,M,y1,y2); for(int i=2;i<=n;++i){ get(i,M,a1,a2); if(a1>y1)y1=a1; if(a2<y2)y2=a2; if(y1>y2){ for(int j=1;j<i;++j){ get(j,M,y1,y2); if(y1>a2||y2<a1){ if(dis(i,j)>r[i]+r[j]+_0)return 0; ld xm=cal(i,j); if(xm>R||xm<L)return 0; if(M<xm)L=M; else R=M; goto out; } } } } return 1; } out:; } } int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;++i)scanf("%llf%llf%llf",x+i,y+i,r+i),r[i]+=_0; if(chk(n))return puts("NIE"),0; int L=1,R=n,M; while(L<R){ M=L+R>>1; if(chk(M))L=M+1; else R=M; } return printf("%d",L),0; }
bzoj1536: [POI2005]Akc- Special Forces Manoeuvres
标签:半径 content div can 抽象 int long ++i desc
原文地址:http://www.cnblogs.com/ccz181078/p/6146790.html