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

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

代码如下:

#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. Unity3D总结:关于射线碰撞

    方法一:Physics.Raycast 光线投射 1.static function Raycast (origin : Vector3, direction : Vector3, distance  ...

  2. canvas 星空插件

    (function(a){ a.fn.starBg=function(p){ var p=p||{}; var w_w=p&&p.window_width?p.window_width ...

  3. Tabs in Non-RootViewController Scenarios

    新建空工程如图 添加一个MainStoryboard如图 设置启动项为MainStoryboard 重写AppDelegate的Window方法 public override UIWindow Wi ...

  4. 继承的文本框控件怎么响应EN_CHANGE等消息

    继承的文本框控件如何响应EN_CHANGE等消息?我从CEdit继承了一个CMyEdit类,想在这个类里填写它的一些消息.我在消息映射表里写的是MESSAGE_HANDLER(EN_CHANGE, O ...

  5. # Playables API(翻译)

        The Playables API provides a way to create tools, effects or other gameplay mechanisms by organi ...

  6. 【BZOJ3218】a + b Problem 可持久化线段树优化建图

    [BZOJ3218]a + b Problem 题解:思路很简单,直接最小割.S->i,容量为Bi:i->T,容量为Wi:所有符合条件的j->new,容量inf:new->i, ...

  7. 九度OJ 1105:字符串的反码 (翻译)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4929 解决:1529 题目描述: 一个二进制数,将其每一位取反,称之为这个数的反码.下面我们定义一个字符的反码.如果这是一个小写字符,则它 ...

  8. 【网络基础系列二】BOOTP、DHCP协议

    BOOTP 含义:BOOT Protocol,引导协议 作用:引导无盘计算机或者第一次启动的计算机获取以下网络配置信息: 主机的IP地址.子网掩码 路由器(网关)的IP地址 DNS服务器IP地址 C/ ...

  9. [数据挖掘课程笔记]Naïve Bayesian Classifier

    朴素贝叶斯模型 1) X:一条未被标记的数据 2) H:一个假设,如H=X属于Ci类 根据贝叶斯公式 把X表示为(x1,x2,....xn) x1,x2,....xn表示X在各个特征上的值. 假设有c ...

  10. vue2.x源码理解

    也不知道哪股风潮,钻研源码竟成了深入理解的标配.我只想说一句,说的很对 准备工作 从GitHub上面下载vue的源码(https://github.com/vuejs/vue) 了解下Flow,Flo ...