hdu 2295(DLX+二分)
用了点离散化的处理, 然后二分一下就可以了。。。
Radar
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1928 Accepted Submission(s): 796
Problem Description
N cities of the Java Kingdom need to be covered by radars for being in a state of war. Since the kingdom has M radar stations but only K operators, we can at most operate K radars. All radars have the same circular coverage with a radius of R. Our goal is to minimize R while covering the entire city with no more than K radars.
Input
The input consists of several test cases. The first line of the input consists of an integer T, indicating the number of test cases. The first line of each test case consists of 3 integers: N, M, K, representing the number of cities, the number of radar stations and the number of operators. Each of the following N lines consists of the coordinate of a city. Each of the last M lines consists of the coordinate of a radar station.
All coordinates are separated by one space. Technical Specification
1. 1 ≤ T ≤ 20 2. 1 ≤ N, M ≤ 50 3. 1 ≤ K ≤ M 4. 0 ≤ X, Y ≤ 1000
All coordinates are separated by one space. Technical Specification
1. 1 ≤ T ≤ 20 2. 1 ≤ N, M ≤ 50 3. 1 ≤ K ≤ M 4. 0 ≤ X, Y ≤ 1000
Output
For each test case, output the radius on a single line, rounded to six fractional digits.
Sample Input
1
3 3 2
3 4
3 1
5 4
1 1
2 2
3 3
Sample Output
2.236068
Source
Recommend
lcy
#include <stdio.h> #include <algorithm> #include <string.h> #include <math.h> #include <iostream> using namespace std; #define N 10000 #define INF 0x3fffffff struct node { double x,y; }gn[55],gm[55]; int n,m,k; int U[N],D[N],R[N],L[N],num[N],H[N],col[N],line[N]; int head,id,mi; int nn,mm; double g[N]; double cal(node t,node t1) { return sqrt( (t.x-t1.x)*(t.x-t1.x)+(t.y-t1.y)*(t.y-t1.y) ); } void prepare() { for(int i=0;i<=mm;i++) { num[i]=0; U[i]=i; D[i]=i; R[i]=i+1; L[i+1]=i; } R[mm]=0; L[0]=mm; memset(H,-1,sizeof(H)); } void link(int tn,int tm) { id++; num[line[id]=tm]++; col[id]=tn; U[D[tm]]=id; D[id]=D[tm]; U[id]=tm; D[tm]=id; if( H[tn]<0 ) H[tn]=R[id]=L[id]=id; else { L[R[H[tn]]]=id; R[id]=R[H[tn]]; L[id]=H[tn]; R[H[tn]]=id; } } int h() { int mark[66]; memset(mark,0,sizeof(mark)); int sum=0; for(int i=R[head];i!=head;i=R[i]) { if(mark[i]==0) { sum++; mark[i]=1; for(int j=D[i];j!=i;j=D[j]) for(int k=R[j];k!=j;k=R[k]) mark[ line[k] ]=1; } } return sum; } void remove(int s) { for(int i=D[s];i!=s;i=D[i]) { R[L[i]]=R[i]; L[R[i]]=L[i]; } } void resume(int s) { for(int i=U[s];i!=s;i=U[i]) R[L[i]]=L[R[i]]=i; } void dfs(int s) { if(s+h()>=mi) return ; if(R[head]==head) { mi=s; return ; } int tmi=INF,tu; for(int i=R[head];i!=head;i=R[i]) { if(num[i]<tmi) { tmi=num[i]; tu=i; } } for(int i=D[tu];i!=tu;i=D[i]) { remove(i); for(int j=R[i];j!=i;j=R[j]) remove(j); dfs(s+1); for(int j=L[i];j!=i;j=L[j]) resume(j); resume(i); } } int DLX(double key) { head=0; mm=n; nn=1; prepare(); id=mm; for(int i=1;i<=m;i++) { int flag=0; for(int j=1;j<=n;j++) { if(cal(gn[j],gm[i]) <= key) { flag=1; link(i,j); } } if(flag==1) nn++; } mi=INF; dfs(0); if(mi<=k) return 1; else return 0; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=n;i++) { scanf("%lf%lf",&gn[i].x,&gn[i].y); } for(int i=1;i<=m;i++) { scanf("%lf%lf",&gm[i].x,&gm[i].y); } int cnt=0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { g[cnt++]=cal(gn[i],gm[j]); } sort(g,g+cnt); int b=0,d=cnt-1; while(b<d) { int mid=(b+d)/2; // 因为是选d 所以要使d绝对不能等于mid if( DLX(g[mid])==1 ) { d=mid; // 要抓住关键的是找最大还最小, 要让=mid 的哪个尽量与mid不相等 } else { b=mid+1; } } double ans; ans=(g[b]*10000000+0.5)/10000000; printf("%.6lf\n",g[b]); } return 0; }