BZOJ1946: [Ceoi2006]antenna

Source: Internet
Author: User

First, the minimum coverage circle is obtained by the stochastic increment method, which is the upper bound of the answer.

Then the two points of the answer, when the test is enumerated each point as the origin, to find the other points are included in the circle of the angle range, and then scan the line.

Time Complexity $o (tn^2\log N) $.

#include <cstdio> #include <cmath> #include <algorithm> #include <cstdlib> #define N 510using  Namespace Std;const double Pi=acos ( -1.0), Eps=1e-8;int n,k,i,j,k;double r,ansr,lim,l,r,mid;struct p{double x, y; P () {} p (double _x,double _y) {x=_x,y=_y;}}  A[n],o,anso;struct e{double X;int t; E () {} e (double _x,int _t) {x=_x,t=_t;}} e[n<<2];inline BOOL CMP (const E&a,const e&b) {return a.x<b.x;} inline double dis (const p&x,const p&y) {return sqrt ((x.x-y.x) * (x.x-y.x) + (X.Y-Y.Y) * (X.Y-Y.Y));} Inline P Center (const p&x,const P&y,const p&z) {double a1=y.x-x.x,b1=y.y-x.y, c1= (A1*A1+B1*B1)/2,a2=z  . x-x.x, B2=z.y-x.y,c2= (A2*A2+B2*B2)/2, D=A1*B2-A2*B1; Return P (x.x+ (C1*B2-C2*B1)/d,x.y+ (A1*C2-A2*C1)/d);}  inline bool exist (int s,double R) {int m=0;    for (int i=0;i<n;i++) if (i!=s) {if (DIS (a[s],a[i]) >r+r+eps) continue;    Double A=atan2 (a[i].y-a[s].y,a[i].x-a[s].x), B=acos (DIS (a[s],a[i])/(R+R));  E[m++]=e (a-b,1);  E[m++]=e (a+b,-1);    E[m++]=e (a-b+pi*2,1);  E[m++]=e (a+b+pi*2,-1);  } sort (e,e+m,cmp);    for (int i=0,ret=1;i<m;i++) if ((ret+=e[i].t) ==k) {ansr=r;    Anso=p (A[s].x+cos (e[i].x) *r,a[s].y+sin (e[i].x) *r);  return 1; } return 0;}  inline bool Check (double R) {for (int i=0;i<n;i++) if (exist (I,R)) return 1; return 0;}  int main () {scanf ("%d%d", &n,&k);  for (i=0;i<n;i++) scanf ("%lf%lf", &a[i].x,&a[i].y);  for (i=0;i<n;i++) swap (A[rand ()%n],a[i]); for (o=a[0],i=1;i<n;i++) if (DIS (a[i],o) >r+eps) for (o=a[i],r=0,j=0;j<i;j++) if (DIS (a[j],o) >r+eps) {O=P (      a[i].x+a[j].x)/2, (A[I].Y+A[J].Y)/2), R=dis (A[i],o);    for (k=0;k<j;k++) if (DIS (a[k],o) >r+eps) O=center (A[k],a[j],a[i]), R=dis (A[i],o);  } lim=ansr=r,anso=o;  R=ansr-eps;    while (l+eps<r) {lim/=2;    if (lim<1e-5) break;    Mid= (L+R)/2;  if (check (mid)) R=mid-eps;else L=mid+eps; } return printf ("%.6f\n%.6f%.6f", ansr,anso.x,anso.y), 0;}

  

BZOJ1946: [Ceoi2006]antenna

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.