题意:给定一个三维空间的一些球和起始位置和结束位置,问你最短要花的时间是多少。

析:建图,所有的位置都建立图,边权就是距离,最小求一次最短路即可。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<double, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-5;
const int maxn = 100 + 10;
const int mod = 1e6;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Point{
double x, y, z, r;
};
Point a[maxn];
double G[maxn][maxn];
double d[maxn];
double distant(int i, int j){
return max(0.0, sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x) + (a[i].y-a[j].y)*(a[i].y-a[j].y) + (a[i].z-a[j].z)*(a[i].z-a[j].z)) - a[i].r - a[j].r);
} double dijkstra(int s, int t){
priority_queue<P, vector<P>, greater<P> >pq;
fill(d, d+n+5, INF);
d[s] = 0.0;
pq.push(P(0.0, s)); while(!pq.empty()){
P p = pq.top(); pq.pop();
if(p.second == t) return p.first;
int u = p.second;
if(d[u] < p.first) continue;
for(int i = 0; i < n+2; ++i){
if(d[i] > d[u] + G[u][i]){
d[i] = d[u] + G[u][i];
pq.push(P(d[i], i));
}
}
}
} int main(){
int kase = 0;
while(scanf("%d", &n) == 1 && n >= 0){
for(int i = 0; i < n; ++i)
scanf("%lf %lf %lf %lf", &a[i].x, &a[i].y, &a[i].z, &a[i].r);
int s = n, t = n+1;
for(int i = n; i < n+2; ++i) scanf("%lf %lf %lf", &a[i].x, &a[i].y, &a[i].z);
a[n].r = a[n+1].r = 0.0;
for(int i = 0; i < n+2; ++i)
for(int j = i+1; j < n+2; ++j)
G[i][j] = G[j][i] = distant(i, j);
double ans = dijkstra(s, t) * 10;
printf("Cheese %d: Travel time = %.f sec\n", ++kase, ans);
}
return 0;
}

UVa 1001 Say Cheese (Dijkstra)的更多相关文章

  1. UVA 1001 Say Cheese 奶酪里的老鼠(最短路,floyd)

    题意:一只母老鼠想要找到她的公老鼠玩具(cqww?),而玩具就丢在一个广阔的3维空间(其实可以想象成平面)上某个点,而母老鼠在另一个点,她可以直接走到达玩具的位置,但是耗时是所走过的欧几里得距离*10 ...

  2. UVA 1001 Say Cheese

    题意: 一只母老鼠想要找到她的玩具,而玩具就丢在一个广阔的3维空间上某个点,而母老鼠在另一个点,她可以直接走到达玩具的位置,但是耗时是所走过的欧几里得距离*10s.还有一种方法,就是靠钻洞,洞是球形的 ...

  3. UVa 1001 Say Cheese【floyd】

    题意:在一个三维的奶酪里面有n(n<=100)个洞,老鼠A想到达老鼠B的位置, 在洞里面可以瞬间移动,在洞外面的移动速度为10秒一个单位,求最短时间 看到n<=100,又是求最短时间,想到 ...

  4. UVA - 1001 Say Cheese(奶酪里的老鼠)(flod)

    题意:无限大的奶酪里有n(0<=n<=100)个球形的洞.你的任务是帮助小老鼠A用最短的时间到达小老鼠O所在位置.奶酪里的移动速度为10秒一个单位,但是在洞里可以瞬间移动.洞和洞可以相交. ...

  5. UVa 1001 奶酪里的老鼠(Dijkstra或Floyd)

    https://vjudge.net/problem/UVA-1001 题意:一个奶酪里有n个洞,老鼠在奶酪里的移动速度为10秒一个单位,但是在洞里可以瞬间移动.计算出老鼠从A点到达O点所需的最短时间 ...

  6. uva 1001(最短路)

    题意:在一个三维的奶酪里面有n(n<=100)个洞,老鼠A想到达老鼠B的位置,在洞里面可以瞬间移动,在洞外面的移动速度为10秒一个单位,求最短时间 题解:如果两个洞相交,那么d[i][j]=0: ...

  7. UVa 10801 Lift Hopping (Dijkstra)

    题意:有一栋100层的大楼(标号为0~99),里面有n个电梯(不超过5个),以及要到达的层数(aid),然后是每个电梯走一层所需的时间, 再n行就是对应每个电梯可以到达的层数,数量不定.然后每装换一次 ...

  8. UVA 11367 - Full Tank? dijkstra+DP

    传送门:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  9. UVa 11374 - Airport Express ( dijkstra预处理 )

    起点和终点各做一次单源最短路, d1[i], d2[i]分别代表起点到i点的最短路和终点到i点的最短路,枚举商业线车票cost(a, b);  ans = min( d1[a] + cost(a, b ...

随机推荐

  1. 6.6.1 F# 中函数调用的类型判断

    6.6.1 F# 中函数调用的类型判断 尽管,在 F# 中能够用尖括号指定类型參数值.与 C# 中的方式同样.但这样的方法非常少使用. 原因是,当编译器无法判断出全部的信息,须要程序猿的帮助时.我们仅 ...

  2. nginx源代码分析--配置信息的继承&amp;合并

    这里仅仅讲述http{}模块下的配置: 在ngx_http_block()函数内(这个函数别调用时在ngx_inti_cycle内的ngx_conf_parse函数,这个函数遇到http命令时 回调n ...

  3. freescale-sdk linux移植一搭建编译环境脚本host-prepare.sh分析

    接下来使用自己的课外歇息时间,对基于PowerPC架构freescale-sdk,进行linux移植和分析.主要參考官方文档freescale linux sdk START_HERE.html,首先 ...

  4. Spring MVC之简单入门

    一.Spring MVC简介: 1.什么是MVC 模型-视图-控制器(MVC)是一个众所周知的以设计界面应用程序为基础的设计模式.它主要通过分离模型(Model).视图(View)及控制器(Contr ...

  5. Jquery 实现标签切换效果

    1.效果图 2.HTML代码如下 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> & ...

  6. c# winform窗体间的传值

    说明:本文讲解两个窗体之间的传值,主要用到两个窗体,form1,form2 1.在form1窗体单击按钮,打开窗体form2,然后把form2中文本框的值传递给form1 form1中的代码: usi ...

  7. java之快速排序

    //基本思想是:通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部数据分别进行快速排序,整个排序过程可以递归进行,以此达到整个数据 ...

  8. DuiLib笔记之Control常用属性

    name 指定控件名称,同一窗口内必须唯一,类型:STRING float 用于指定控件是否使用绝对定位,或设置FloatPercent,类型:BOOL,默认值为false,格式:float=&quo ...

  9. Snow White,摘自iOS应用Snow White and more stories

    Once upon a time, there was a land. 从前,有个国度. It was ruled by an evil queen. 它被一位邪恶的女王统治. Every day t ...

  10. Oracle 11gR2 使用RMAN Duplicate复制数据库

    Oracle 11gR2 使用RMAN Duplicate复制数据库     前言:     上周刚做完一个项目,用户要求RAC的数据库可以自己主动备份到另外一个单节点上,单节点可以正常拿起来就能用. ...