Cosmic Rays

6487: Cosmic Rays

时间限制: 1 Sec   内存限制: 128 MB
提交: 76   解决: 37
[ 提交][ 状态][ 讨论版][命题人: admin]

题目描述

On the xy-plane, Snuke is going to travel from the point (xs,ys) to the point (xt,yt). He can move in arbitrary directions with speed 1. Here, we will consider him as a point without size.
There are N circular barriers deployed on the plane. The center and the radius of the i-th barrier are (xi,yi) and ri, respectively. The barriers may overlap or contain each other.
A point on the plane is exposed to cosmic rays if the point is not within any of the barriers.
Snuke wants to avoid exposure to cosmic rays as much as possible during the travel. Find the minimum possible duration of time he is exposed to cosmic rays during the travel.

Constraints
All input values are integers.
−109≤xs,ys,xt,yt≤109
(xs,ys) ≠ (xt,yt)
1≤N≤1,000
−109≤xi,yi≤109
1≤ri≤109

输入

The input is given from Standard Input in the following format:
xs ys xt yt
N
x1 y1 r1
x2 y2 r2
:
xN yN rN

输出

Print the minimum possible duration of time Snuke is exposed to cosmic rays during the travel. (精确到小数点后9位)

样例输入

-2 -2 2 2
1
0 0 1

样例输出

3.656854249

提示

An optimal route is as follows:



问题:给定起点和终点,其中会经过n堡垒,每个堡垒会有半径为r的保护罩,有保护伞的地方不会受到宇宙辐射,没有保护罩的地方会受到宇宙射线的辐射。飞机速度为1,求飞机最短的受到宇宙辐射的路程。
分析:把终点起点填加进来,跑一个最短路,用long double。

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
struct node
{
    int x,y,r;
}e[1005];

int n,sx,sy,ex,ey;
long double mp[1005][1005],dis[1005];
int vis[MAX];

void dijkstra()
{
    int i,j,indx;
    long double temp;
    memset(vis,0,sizeof(vis));
    
    vis[1]=1;
    for(i=1;i<=n;i++)
        dis[i]=mp[1][i];
    
    dis[1]=0;
    for(i=2;i<=n;i++)
    {
        indx=0;
        temp=1e18;
        
        for(j=1;j<=n;j++)
        {
            if(temp>dis[j] && !vis[j])
            {
                indx=j;
                temp=dis[j];
            }
        }
        
        if(!indx)
            break;
        
        vis[indx]=1;
        
        for(j=1;j<=n;j++)
        {
            if(dis[j]>dis[indx]+mp[indx][j] && !vis[j])
                dis[j]=mp[indx][j]+dis[indx];
        }
    }
    printf("%.9Lf\n",dis[n]);
}

int main()
{
    int i,j;
    for(i=0;i<1005;i++)
        e[i].r=0;
    
    scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
    scanf("%d",&n);
    for(i=2;i<=n+1;i++)
        scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].r);
    
    n=n+2;
    e[n].x=ex;
    e[n].y=ey;
    e[1].x=sx;
    e[1].y=sy;
    
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            mp[i][j]=(long double)sqrt((long double)(e[i].x-e[j].x)*(e[i].x-e[j].x)+(long double)(e[i].y-e[j].y)*(e[i].y-e[j].y));
            mp[i][j]=mp[i][j]-e[i].r-e[j].r;
            if(mp[i][j]<0)
                mp[i][j]=0;
            mp[j][i]=mp[i][j];
        }
    }
    
    dijkstra();
    
    return 0;
}


内容概要:本文介绍了基于SMA-BP黏菌优化算法优化反向传播神经网络(BP)进行多变量回归预测的项目实例。项目旨在通过SMA优化BP神经网络的权重和阈值,解决BP神经网络易陷入局部最优、收敛速度慢及参数调优困难等问题。SMA算法模拟黏菌寻找食物的行为,具备优秀的全局搜索能力,能有效提高模型的预测准确性和训练效率。项目涵盖了数据预处理、模型设计、算法实现、性能验证等环节,适用于多变量非线性数据的建模和预测。; 适合人群:具备一定机器学习基础,特别是对神经网络和优化算法有一定了解的研发人员、数据科学家和研究人员。; 使用场景及目标:① 提升多变量回归模型的预测准确性,特别是在工业过程控制、金融风险管理等领域;② 加速神经网络训练过程,减少迭代次数和训练时间;③ 提高模型的稳定性和泛化能力,确保模型在不同数据集上均能保持良好表现;④ 推动智能优化算法与深度学习的融合创新,促进多领域复杂数据分析能力的提升。; 其他说明:项目采用Python实现,包含详细的代码示例和注释,便于理解和二次开发。模型架构由数据预处理模块、基于SMA优化的BP神经网络训练模块以及模型预测与评估模块组成,各模块接口清晰,便于扩展和维护。此外,项目还提供了多种评价指标和可视化分析方法,确保实验结果科学可信。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值