Cosmic Rays

时间限制: 1 Sec  内存限制: 128 MB

题目描述

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:

来源

ABC048&ARC064

Submit State

首先要看出这是最短路,然后处理每个点之间的距离等于圆心的距离减两个半径
如果maze是负数,就变成0;

AC 代码

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include<math.h>
using namespace std;
#define inf 0x3f3f3f3f
#define N 1005
double maze[N][N],dis[N];
int n;
int vis[N];
void Dijkstra()
{int i,j,minn,indx;memset(vis,0,sizeof(vis));vis[0] = 1;for(i = 0; i<=n+1; i++)dis[i] = maze[0][i];for(i = 1; i<=n+1; i++){minn = inf;for(j = 1; j<=n+1; j++){if(dis[j]<minn && !vis[j]){indx = j;minn = dis[j];}}vis[indx] = 1;for(j = 1; j<=n+1; j++){if(!vis[j] && dis[indx]+maze[indx][j]<dis[j])dis[j] = dis[indx]+maze[indx][j];}}
}struct node
{int x;int y;int r;
} s[N];
int main()
{int xx,yy;scanf("%d%d%d%d",&s[0].x,&s[0].y,&xx,&yy);s[0].r=0;scanf("%d",&n);for(int i=0;i<=n+1;i++)for(int j=0;j<=n+1;j++)maze[i][j]=inf;s[n+1].x=xx;s[n+1].y=yy;s[n+1].r=0;for(int i=1; i<=n; i++)scanf("%d%d%d",&s[i].x,&s[i].y,&s[i].r);for(int i=0; i<=n+1; i++){for(int j=i+1; j<=n+1; j++){maze[i][j]=(long double)sqrt((long double)(s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y));maze[i][j]-=s[i].r+s[j].r;if(maze[i][j]<0)maze[i][j]=0;maze[j][i]=maze[i][j];}}Dijkstra();printf("%.9lf\n",dis[n+1]);return 0;
}
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1010;
int n;
const long double inf=1e37;
struct node
{int x,y,r;
}s[maxn];
double maze[maxn][maxn];
double dis[maxn];
bool vis[maxn];
void dijkstra(int s)
{dis[s]=0;while(1){int v=-1;for(int i=0;i<=n+1;i++){if(!vis[i]&&(v==-1||dis[i]<dis[v])) v=i;}if(v==-1) break;vis[v]=1;for(int i=0;i<=n+1;i++)dis[i]=min(dis[i],dis[v]+maze[v][i]);}
}
int init()
{for(int i=0;i<=n+1;i++)for(int j=0;j<=n+1;j++)maze[i][j]=inf;
}
int main()
{int enx,eny;scanf("%d%d%d%d",&s[0].x,&s[0].y,&enx,&eny);scanf("%d",&n);s[n+1].x=enx;s[n+1].y=eny;init();for(int i=1;i<=n;i++){scanf("%d%d%d",&s[i].x,&s[i].y,&s[i].r);}for(int i=0;i<=n+1;i++){for(int j=i+1;j<=n+1;j++){maze[i][j]=(double)sqrt((double)(s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y));maze[i][j]-=s[i].r+s[j].r;if(maze[i][j]<0)maze[i][j]=0;maze[j][i]=maze[i][j];}}for(int i=0;i<=n+1;i++)dis[i]=inf;dijkstra(0);printf("%.9lf\n",dis[n+1]);return 0;
}

Cosmic Rays(最短路变形)相关推荐

  1. Cosmic Rays

    6487: Cosmic Rays 时间限制: 1 Sec   内存限制: 128 MB 提交: 76   解决: 37 [ 提交][ 状态][ 讨论版][命题人: admin] 题目描述 On th ...

  2. Cosmic Rays(dijsktra)

    6487: Cosmic Rays 时间限制: 1 Sec  内存限制: 128 MB 题目描述 On the xy-plane, Snuke is going to travel from the ...

  3. poj 2263 最短路变形——最小边的最大值

    文章目录 本题:最短路变形--最小边的最大值 最短路变形--最大边的最小值 本题:最短路变形--最小边的最大值 最短路变形--最大边的最小值 poj2253

  4. poj 2253 最短路变形——最大边的最小值

    文章目录 本题:最短路变形--最大边的最小值 最短路变形--最小边的最大值 本题:最短路变形--最大边的最小值 题意: 给出两只青蛙.以及其他石头的坐标,需要求出可以到达另一只青蛙的所有路径中,青蛙跳 ...

  5. 【图论-最短路变形】想越狱的小杉

    [图论-最短路变形]想越狱的小杉 Time Limit:1000MS  Memory Limit:65536K Description 背景 Background 这次小杉来到了经典美剧<越狱& ...

  6. poj 1797(最短路变形)

    题目链接:http://poj.org/problem?id=1797 思路:题目意思很简单,n个顶点,m条路,每条路上都有最大载重限制,问1->n最大载重量.其实就是一最短路的变形,定义wei ...

  7. nyoj 307(最短路变形)

    解题思路:这道题和上一道题一样,也是最短路的变形,我之前的想法是二分答案,然后再dp去判断是否可以满足要求,但发现这样子的话会存在问题:因为一条路可能走多次,就无法保证其后效性. 看了别人的思路:先以 ...

  8. 最小花费(最短路变形+中南大学复试机试)

    题目描述 在n个人中,某些人的银行账号之间可以互相转账.这些人之间转账的手续费各不相同.给定这些人之间转账时需要从转账金额里扣除百分之几的手续费,请问A最少需要多少钱使得转账后B收到100元. 输入 ...

  9. L3-007. 天梯地图 -最短路变形

    L3-007. 天梯地图 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 本题要求你实现一个天梯赛专属在线地图,队员输入自己学校 ...

最新文章

  1. React,Redux,React-redux的错综复杂关系
  2. 微服务网关Gateway中Path路径过滤
  3. 陈松松:如何锁定细分领域,视频营销才更容易持续做下去
  4. Swift学习笔记(10)--枚举
  5. 视频编辑软件(Nero Video2021中文版) v23.0.1.12pjb
  6. Insyde uefi 隐藏设置_苹果手机:插件NoMessageButtons:可隐藏iOS信息应用界面的按钮...
  7. 启动IDEA时出现error launching idea failed to create jvm的解决办法
  8. 谷歌李开复:我的传奇人生源于十句箴言
  9. [ZJOI2008]无序运动Movement
  10. C语言写货郎问题(贪心算法)
  11. 深度学习方法在负荷预测中的应用综述(论文阅读)
  12. 1646906-26-4,PO-T2T钌(Ⅱ)多吡啶配合物[Ru(phen)(Hecip)](ClO4)2
  13. SpringCloud简介及注册中心Eureka
  14. word表格和后面的文字间距太小
  15. oracle物料期初余额,【YOU学吧】NC产品库存管理期初业务详解
  16. 虚拟摄像头该如何实现
  17. 头发为什么会从中间断掉_头发总是从中间断怎么办 几个妙招让你告别脱发问题...
  18. java ?: 的使用
  19. Grin接盘显卡算力?机构分析称Grin市值2019年有望挤进前40
  20. js charCodeAt, fromCharCode 字符与Unicode编码转换

热门文章

  1. 迭代、可迭代对象、迭代器、生成器、for循环、iter()函数与next()函数的概念及关系
  2. 还有34天18年就过完了, 收好这份2019区块链行业指南
  3. html站点地图是什么,网站地图(sitemap)是什么意思?网站地图标签介绍
  4. 《怪物猎人:世界》背后潜藏的真实生态学
  5. django自带的加密方法
  6. 编译配置(1)——ARMv7,ARMv8(AArch64) 浮点配置等相关知识
  7. 一博科技IPO破发:公司市值50亿 深圳南山区上市公司数达200家
  8. eclipse rcp_品牌化您的Eclipse RCP应用程序
  9. iptables深入解析-mangle篇
  10. log_format为nginx设置日志格式