zoukankan      html  css  js  c++  java
  • UPC-6487 Cosmic Rays(SPFA最短路)

    题目描述
    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:
    这里写图片描述

    题意:在二维平面上给一个起点坐标一个终点坐标,给出有k块区域,每块区域是一个半径为ri的圆,给出每块区域的圆心坐标和半径,从起点移动到终点速度是1,移动过程中,在圆形区域内是不受某某射线的辐射的,因此要求从起点到终点收到辐射的最少时间。

    把起点和终点和每个圆形区域圆心看做一个点,两点之间都有一条边,边权为两点距离,即收到辐射的时间,因为在圆形区域内不受射线,因此距离减去半径即每条边的边权,若两圆心距离小于两圆形区域半径之和,即该边权为0,从起点到终点跑一条最短路即可。

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=1e3+10;
    double dist[maxn],mp[maxn][maxn];
    bool vis[maxn];
    int n;
    void SPFA(int s)
    {
        queue<int>q;
        while(!q.empty())q.pop();
        for(int i=0; i<=n; i++)dist[i]=1e10;
        memset(vis,false,sizeof vis);
        dist[s]=0;
        vis[s]=true;
        q.push(s);
        while(!q.empty())
        {
            int top=q.front();
            q.pop();
            vis[top]=false;
            for(int i=1; i<=n; i++)
            {
                if(dist[i]>dist[top]+mp[top][i])
                {
                    dist[i]=dist[top]+mp[top][i];
                    if(!vis[i])
                    {
                        vis[i]=true;
                        q.push(i);
                    }
                }
            }
        }
    }
    double cal(double x1,double y1,double x2,double y2)
    {
        return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    }
    double x[maxn],y[maxn],r[maxn];
    int main()
    {
        while(scanf("%lf%lf%lf%lf",&x[1],&y[1],&x[2],&y[2])!=EOF)
        {
            scanf("%d",&n);
            n+=2;
            r[1]=r[2]=0;
            mp[2][1]=mp[1][2]=cal(x[1],y[1],x[2],y[2]);
            for(int i=3; i<=n; i++)
            {
                scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);
                for(int j=1; j<i; j++)
                {
                    double tmp=cal(x[i],y[i],x[j],y[j]);
                    if(r[i]+r[j]>tmp) mp[j][i]=0;
                    else mp[i][j]=mp[j][i]=tmp-r[i]-r[j];
                }
            }
            SPFA(1);
            printf("%.9f
    ",dist[2]);
        }
    }
    
  • 相关阅读:
    PHP中GBK和UTF8乱码解决方案
    Ubuntu下的PHP开发环境架设
    Windows 7 IE主页被篡改,如何修复?
    提高代码质量:如何编写函数
    PhpStorm 10 破解方法
    PHP 常用的header头部定义汇总
    kindle 退出演示模式
    好程序与差程序Good Programming, Bad Programming
    如何让你的一天能有26小时?不完全是开玩笑
    毕业若干年,才知道自己原来认为的很多都是错的想法的成熟
  • 原文地址:https://www.cnblogs.com/kuronekonano/p/11135762.html
Copyright © 2011-2022 走看看