hdu 2295 Radar 重复覆盖 DLX+二分答案 给出一些城市及一些雷达的坐标,要求从这些雷达中选取最多k个能够覆盖所有的城市,问雷达的最小覆盖半径为多少

本文深入探讨了深度学习技术在音视频处理领域的应用,包括AI音视频处理、图像处理AR特效、音视频直播流媒体等方向,详细阐述了各领域的关键技术和实际案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
 

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

//


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define eps 1e-8
#define N 85
#define V 36000
int n,m,K;//n行 m列 K限制条件,最多用K行(仅限于此题)
int L[V],R[V];
int D[V],U[V];
int C[V];
int S[N],H[N];
int ak,size;//ak 最少多少行可以覆盖所有列(可重复)
double dis(double x1,double y1,double x2,double y2)
{
    return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
}
void Link(int r,int c)
{
    S[c]++;C[size]=c;
    U[size]=U[c];D[U[c]]=size;
    D[size]=c;U[c]=size;
    if(H[r]==-1) H[r]=L[size]=R[size]=size;
    else
    {
        L[size]=L[H[r]];R[L[H[r]]]=size;
        R[size]=H[r];L[H[r]]=size;
    }
    size++;
}
void remove(int c)
{
    int i;
    for(i=D[c];i!=c;i=D[i])
        L[R[i]]=L[i],R[L[i]]=R[i];
}
void resume(int c)
{
    int i;
    for(i=U[c];i!=c;i=U[i])
        L[R[i]]=R[L[i]]=i;
}
int h()
{
    int i,j,k,count=0;
    bool visit[N];
    memset(visit,0,sizeof(visit));
    for(i=R[0];i;i=R[i])
    {
        if(visit[i]) continue;
        count++;
        visit[i]=1;
        for(j=D[i];j!=i;j=D[j])
        {
            for(k=R[j];k!=j;k=R[k])
                visit[C[k]]=1;
        }
    }
    return count;
}
void Dance(int k)
{
    int i,j,c,Min,ans;
    ans=h();
    if(k+ans>K) return ;//仅限于此题
    if(k+ans>=ak) return;
    if(!R[0])
    {
        if(k<ak) ak=k;
        return;
    }
    for(Min=N,i=R[0];i;i=R[i])
        if(S[i]<Min) Min=S[i],c=i;
    for(i=D[c];i!=c;i=D[i])
    {
        remove(i);
        for(j=R[i];j!=i;j=R[j])
            remove(j);
        Dance(k+1);
        for(j=L[i];j!=i;j=L[j])
            resume(j);
        resume(i);
    }
    return;
}
double d[66][66];
double dl[66*66];
int main()
{
    int i,j,ncase;
    double x[N],y[N],x1[N],y1[N];
    int left,right,mid;
    double ans;
    scanf("%d",&ncase);
    while(ncase--)
    {
        //村庄当成列m,卫星站当成行n  最多用K个卫星站
        scanf("%d%d%d",&m,&n,&K);
        for(i=1;i<=m;i++)
            scanf("%lf%lf",&x[i],&y[i]);
        for(i=1;i<=n;i++)
            scanf("%lf%lf",&x1[i],&y1[i]);
        int num = 0;
for (i = 1; i <= n; ++i) {
for (j = 1; j <= m; ++j) {
d[i][j]=dl[num++] = dis(x1[i],y1[i],x[j], y[j]);
}
}
//二分答案这里要注意:如果直接left=0,right=(1<<30)直接二分 时间花费比较多
//这里要把所有距离先排序 二分枚举这些距离  AC
sort(dl, dl + num);
num = unique(dl, dl + num) - dl;
        left=0;
        right= num-1;
        ans=dl[right];
        while(left<right)
        {
            //DLX
            for(i=0;i<=m;i++)
            {
                S[i]=0;
                U[i]=D[i]=i;
                L[i+1]=i;R[i]=i+1;
            }R[m]=0;
            memset(H,-1,sizeof(H));
            size=m+1;
            mid=(left+right)/2;
            for(i=1;i<=n;i++)
            {
                for(j=1;j<=m;j++)
                    if(dl[mid]>=d[i][j])  Link(i,j);
            }
            ak=N;
            Dance(0);
            //......
            if(ak<=K) {ans=min(ans,dl[mid]);right=mid;}
            else left=mid+1;
        }
        printf("%.6lf\n",ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值