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

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

代码如下:

#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. spring+mybatis多数据源,动态切换

    有时我们项目中需要配置多个数据源,不同的业务使用的数据库不同 实现思路:配置多个dataSource ,再配置多个sqlSessionFactory,和dataSource一一对应.重写SqlSess ...

  2. 九度OJ 1120:全排列 (DFS)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4471 解决:1139 题目描述: 给定一个由不同的小写字母组成的字符串,输出这个字符串的所有全排列. 我们假设对于小写字母有'a' < ...

  3. ZeroMQ Distributed Messaging

    ZeroMQ \zero-em-queue\, \ØMQ\: Ø  Connect your code in any language, on any platform. Ø  Carries mes ...

  4. HDFS HBase Solr Which one?

    从访问模式角度决策 HDFS 压缩性能最优.扫描速度最快:不支持随机访问,仅支持昂贵.复杂的文件查询 HBase适合随机访问 Solr 适合检索需求 HBase访问单个记录的时间为毫秒级别,而HDFS ...

  5. 阿里Java开发手册学习 3 MYSQL规约

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  6. 解决shell脚本“syntax error near unexpected token `fi'”的问题。

    执行shell脚本的时候,提示如下错误: 查询资料后发现: 执行: vi finddir.sh 然后,输入 :set ff 结果是: 解决方案就是,修改为unix: :set ff=unix 执行保存 ...

  7. 腾讯云服务器申请免费SSL证书,实现Https。

    1.首先在腾讯云的SSL证书管理中申请免费的SSL.审核速度还是挺快的... 2.按照步骤申请后,就可以下载主流web服务器的证书了.如图: 3.这里我使用的web服务器是nginx,把nginx下的 ...

  8. 关于“telnet localhost:8080不能打开到主机的连接, 在端口 23: 连接失败”问题

    你的命令写错了!不是telnet localhost:1433 是 telnet localhost 1433 不要那个:号 http://www.fengfly.com/ 答案补充 :“正在连接到l ...

  9. 在windows下把Mongodb设置系统服务

    把Mongodb Server 设置为系统,方便启动与停止 今天一时兴起在本地安装了下Mongodb服务,安装完后,创建了配置文件为数据库服务指明在哪里存储数据库原始文件,随即就启动了mongo se ...

  10. HDU5968 异或密码 —— 二分 + 边界的细节处理

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5968 异或密码 Time Limit: 2000/1000 MS (Java/Others)    M ...