HDU 2295 Radar (DLX可重复覆盖+二分)

该博客介绍了一种解决用最少数量的雷达覆盖所有城市的算法。通过二分枚举雷达的半径,构建覆盖表并判断是否能用少于K个雷达覆盖所有城市。当找到满足条件的最小半径时,二分搜索结束。

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

题意:

给出N个城市的坐标,M个雷达的坐标,求用少于K个雷达站覆盖所有城市的最小雷达半径(所有启用的雷达站的半径都一样)

思路:
二分枚举半径,每次枚举得到一组覆盖表,对这张表进行覆盖,看能不能用少于K个雷达覆盖所有城市。

若能向左(半径减小)继续二分,若不能向右(半径增大)继续二分。直到精度误差满足要求二分停止。

代码:

#include <bits/stdc++.h>
#define mid (le+ri)/2;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int maxn=230;
const double eps=1e-7;
int L[maxn*maxn],R[maxn*maxn],U[maxn*maxn],D[maxn*maxn];//节点的上下左右四个方向的链表
int C[maxn*maxn],H[maxn],cnt[maxn],vis[maxn];//C列H行cnt列链表中元素个数
int n,m,id,fans,T,lim,cut;
double le,ri,ans;
typedef struct Node{
    int x;int y;
    Node(int xx=0,int yy=0){x=xx;y=yy;}
}Node;
Node city[60];
Node rad[60];
void init(){
    for(int i=0;i<=cut;i++){
        cnt[i]=0;U[i]=D[i]=i;
        L[i+1]=i;R[i]=i+1;
    }
    R[cut]=0;id=cut+1;
    memset(H,-1,sizeof(H));
}
void Link(int r,int c){
    cnt[c]++;C[id]=c;
    U[id]=U[c];D[U[c]]=id;
    D[id]=c;U[c]=id;
    if(H[r]==-1) H[r]=L[id]=R[id]=id;
    else{
        L[id]=L[H[r]];R[L[H[r]]]=id;
        R[id]=H[r];L[H[r]]=id;
    }
    id++;
}
void Remove(int Size){
    for(int j=D[Size];j!=Size;j=D[j])
        L[R[j]]=L[j],R[L[j]]=R[j];
}
void Resume(int Size){
    for(int j=D[Size];j!=Size;j=D[j])
        L[R[j]]=R[L[j]]=j;
}
int h()
{
    int sum=0;
    memset(vis,0,sizeof(vis));
    for(int i=R[0];i;i=R[i]){
        if(vis[i]) continue;
        sum++;
        for(int j=D[i];j!=i;j=D[j]){
            for(int k=R[j];k!=j;k=R[k])
                vis[C[k]]=1;
        }
    }
    return sum;
}
void Dance(int k){
    int mm=maxn,pos;
    if(k+h()>=fans) return;
    if(!R[0]){
        if(k<fans) fans=k;
        return;
    }
    for(int i=R[0];i;i=R[i])
        if(mm>cnt[i]) mm=cnt[i],pos=i;

    for(int i=D[pos];i!=pos;i=D[i])
    {
        Remove(i);
        for(int j=R[i];j!=i;j=R[j]) Remove(j);
        Dance(k+1);
        for(int j=R[i];j!=i;j=R[j]) Resume(j);
        Resume(i);
    }
}
int get(double dis){
    init();
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
        if(sqrt((rad[i].x-city[j].x)*(rad[i].x-city[j].x)+(rad[i].y-city[j].y)*(rad[i].y-city[j].y))<=dis){
            Link(i+1,j+1);
        }
    }

    fans=lim+1;
    Dance(0);
    return fans;
}
int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d",&m,&n,&lim);
        cut=m;
        for(int i=0;i<m;i++)
            scanf("%d%d",&city[i].x,&city[i].y);
        for(int i=0;i<n;i++)
            scanf("%d%d",&rad[i].x,&rad[i].y);
        le=0;
        ri=sqrt(1001*1001);
        while((ri-le)>eps){
            ans=mid;
            if(get(ans)<=lim){
                ri=mid;
            }else{
                le=mid;
            }
        }
        printf("%.6lf\n",ans);
    }
}
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


内容概要:本文针对国内加密货币市场预测研究较少的现状,采用BP神经网络构建了CCi30指数预测模型。研究选取2018年3月1日至2019年3月26日共391天的数据作为样本,通过“试凑法”确定最优隐结点数目,建立三层BP神经网络模型对CCi30指数收盘价进行预测。论文详细介绍了数据预处理、模型构建、训练及评估过程,包括数据归一化、特征工程、模型架构设计(如输入层、隐藏层、输出层)、模型编译与训练、模型评估(如RMSE、MAE计算)以及结果可视化。研究表明,该模型在短期内能较准确地预测指数变化趋势。此外,文章还讨论了隐层节点数的优化方法及其对预测性能的影响,并提出了若干改进建议,如引入更多技术指标、优化模型架构、尝试其他时序模型等。 适合人群:对加密货币市场预测感兴趣的研究人员、投资者及具备一定编程基础的数据分析师。 使用场景及目标:①为加密货币市场投资者提供一种新的预测工具和方法;②帮助研究人员理解BP神经网络在时间序列预测中的应用;③为后续研究提供改进方向,如数据增强、模型优化、特征工程等。 其他说明:尽管该模型在短期内表现出良好的预测性能,但仍存在一定局限性,如样本量较小、未考虑外部因素影响等。因此,在实际应用中需谨慎对待模型预测结果,并结合其他分析工具共同决策。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值