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;
}

Cosmic Rays相关推荐

  1. Cosmic Rays(dijsktra)

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

  2. Cosmic Rays(最短路变形)

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

  3. 你知道cosmic吗

    是的,我知道."cosmic" 有多个意思,它可以指宇宙的,也可以指非常高尚或神圣的.例如,"cosmic rays" 指的是宇宙中的射线,而 "co ...

  4. 时隔16年,Science再次发布“全世界最前沿的125个科学问题”!

    点击上方"视学算法",选择加"星标"或"置顶" 重磅干货,第一时间送达 <科学>杂志曾于创刊125周年之际发布过125个推动基础 ...

  5. 我们生活在一个虚拟世界的概率有多大?

    © Thomas Leuthard - Flickr 来源:人工智能AI技术 利维坦按: 我们在以前的文章中介绍过约翰·惠勒提出的延迟实验: 第一步: 我们拿一块经过半镀银处理的反射镜BS1来代替双缝 ...

  6. 《Two Dozen Short Lessons in Haskell》学习(十六)- Definitions with Alternatives

    <Two Dozen Short Lessons in Haskell>(Copyright © 1995, 1996, 1997 by Rex Page,有人翻译为Haskell二十四学 ...

  7. AtCoder Regular Contest 064

    文章目录 C - Boxes and Candies D - An Ordinary Game E - Cosmic Rays F - Rotated Palindromes C - Boxes an ...

  8. 【POJ - 2392】Space Elevator (dp,优秀的背包问题)

    题干: The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a ...

  9. 新版:全世界最前沿的125科学问题

    "我们可以生活在一个去化石燃料的世界中吗?""意识存在于何处?""为什么时间似乎只朝一个方向流动?"--今天(4月10日)下午,上海交通大学 ...

最新文章

  1. python+requests+unittest+excel_接口自动化测试 unittest+request+excel(踩‘坑’)
  2. 一个小灯泡引发大论战:千万粉丝科普up主翻车,伊朗“唐马儒”、李永乐等下场,30万公里导线引百万网友围观...
  3. CV:利用cv2自带两步法haarcascade_frontalcatface.xml实现对猫脸检测
  4. 【AI-1000问】你知道为什么GoogLeNet也被称为InceptionNet吗?
  5. linux nginx 代理iis,nginx 系列 linux下安装以及配置IIS分发
  6. 计算机集成制造 pdf,计算机集成制造系统方法论9412536127640μ.pdf
  7. SQL Server 自定义函数 返回树结构函数
  8. 指向函数的指针 - C语言
  9. 什么软件测试显示器响应时间准,自己动手测试液晶显示器响应时间
  10. JAVA SAX解析XML文档
  11. 【Hbase】命令行load数据文件到Hbase
  12. 消息最终一致性解决方案之RabbitMQ实现
  13. 使用通达信获取股票历史数据
  14. java 错误: 无法将类 Customer中的构造器 Customer应用到给定类型
  15. 运算放大器单电源设计
  16. <C++>类的对象内存空间分配一点就通,this指针一学就会
  17. java给图片加水印
  18. Unity Cinemachine之第三人称摄像机CinemachineFreeLook属性详解
  19. 数据挖掘思维和实战24 实践 5:使用 fatText 进行新闻文本分类
  20. TraceId 搭配 ELK,碉堡了

热门文章

  1. 深夜学姐问我在Vue中Echarts柱状图如何自定义顶部亮点
  2. Zabbix中禁用guest用户
  3. 【D3js】d3.select(this)获取到的 DOM对象的数据结构
  4. [5GC]《5G核心网-赋能数字化时代》| 6.1 PDU会话的概念
  5. 我在终端里养了个猫娘
  6. Linux Netfilter mangle表注册
  7. addslashes是用PHP,如何在PHP中使用addslashes()函数?
  8. nginx代理去掉URl前缀
  9. 计算机网络学习-007
  10. 计算机科学计算答案豆丁,2020美术鉴赏网课答案豆丁网