Test instructions
n points, and then build M fire stations.
Ask the minimum of the maximum distance from the fire station to each point.
Ideas:
DLX directly two points to determine the tle.
At this time a very ingenious idea
The distance we seek must be the distance between two points.
So let's go over the distance and sort it out.
Then use the subscript two points to get AC.
Code:
#include "stdio.h" #include "algorithm" #include "string.h" #include "iostream" #include "Cmath" #include "queue" #include "Map" #include "vector" #include "string" using namespace std; #define EPS 1e-6#define N 55*55#define RN 55#define CN 55double Dist[n];int kx;struct dlx{int n,m,c; int u[n],d[n],l[n],r[n],row[n],col[n]; int H[RN],S[CN],CNT,ANS[RN]; void init (int _n,int _m) {n=_n; M=_m; for (int i=0; i<=m; i++) {s[i]=0; U[i]=d[i]=i; L[i]= (i==0?m:i-1); R[i]= (i==m?0:i+1); } c=m; for (int i=1; i<=n; i++) h[i]=-1; } void link (int x,int y) {C + +; Row[c]=x; Col[c]=y; s[y]++; U[c]=u[y]; D[c]=y; D[u[y]]=c; U[y]=c; if (h[x]==-1) h[x]=l[c]=r[c]=c; else {l[c]=l[h[x]]; R[C]=H[X]; R[l[h[x]]]=c; L[h[x]]=c; }} void del (int x) {for (int i=d[x]; i!=x; i=D[i]) {r[l[i]]=r[i]; L[r[i]]=l[i]; }} void Rec (int x) {for (int i=u[x]; i!=x; I=u[i]) {r[l[i]]=i; L[r[i]]=i; }} int USED[CN]; int h () {int sum=0; for (int i=r[0]; i!=0; i=r[i]) used[i]=0; for (int i=r[0]; i!=0; I=r[i]) {if (used[i]==0) {sum++; Used[i]=1; For (int. j=d[i]; j!=i; j=d[j]) for (int k=r[j]; k!=j; k=r[k]) used[col[k]]=1; }} return sum; } int Dance (int x) {if (X+h () >=cnt | | x+h () >KX) return 0; if (r[0]==0) {cnt=min (cnt,x); if (CNT<=KX) return 1; return 0; } int now=r[0]; for (int i=r[0]; i!=0; I=r[i]) {if (S[i]<s[now]) now=i; } for (int i=d[now]; i!=now; I=d[i]) {del (i); for (int j=r[i]; j!=i; J=R[J]) del (j); if (dance (x+1)) return 1; for (int j=l[i]; j!=i; j=l[j]) rec (j); Rec (i); } return 0; }} dlx;struct node{double x, Y,} dian[55];d ouble dis (double x1,double y1,double x2,double y2) {return sqrt ((x1-x2) * ( X1-X2) + (y1-y2) * (Y1-y2));} int main () {int t; cin>>t; while (t--) {int n; scanf ("%d%d", &n,&kx); for (int i=1;i<=n;i++) scanf ("%lf%lf", &dian[i].x,&dian[i].y); int cnt=0; for (int i=1;i<=n;i++) {for (int j=i;j<=n;j++) {Dist[cnt++]=dis (Dian[i]. X,DIAN[I].Y,DIAN[J].X,DIAN[J].Y); }} sort (dist,dist+cnt); int l=0,r=cnt-1; Double ans; while (l<=r) {int mid= (L+R)/2; Dlx.init (N,n); for (int i=1;i<=n;i++) {for (int j=1;j<=n;j++) {Double T Ep=dis (Dian[i].x,dian[I].Y,DIAN[J].X,DIAN[J].Y]; if (Tep>dist[mid]) continue; Dlx.link (I,J); }} dlx.cnt=999; if (dlx.dance (0)) {Ans=dist[mid]; R=mid-1; } else l=mid+1; } printf ("%.6f\n", ans); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
[DLX Repeat overlay] HDU 3656 Fire Station