UVa 1001 Say Cheese (Dijkstra)
题意:给定一个三维空间的一些球和起始位置和结束位置,问你最短要花的时间是多少。
析:建图,所有的位置都建立图,边权就是距离,最小求一次最短路即可。
代码如下:
#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)的更多相关文章
- UVA 1001 Say Cheese 奶酪里的老鼠(最短路,floyd)
题意:一只母老鼠想要找到她的公老鼠玩具(cqww?),而玩具就丢在一个广阔的3维空间(其实可以想象成平面)上某个点,而母老鼠在另一个点,她可以直接走到达玩具的位置,但是耗时是所走过的欧几里得距离*10 ...
- UVA 1001 Say Cheese
题意: 一只母老鼠想要找到她的玩具,而玩具就丢在一个广阔的3维空间上某个点,而母老鼠在另一个点,她可以直接走到达玩具的位置,但是耗时是所走过的欧几里得距离*10s.还有一种方法,就是靠钻洞,洞是球形的 ...
- UVa 1001 Say Cheese【floyd】
题意:在一个三维的奶酪里面有n(n<=100)个洞,老鼠A想到达老鼠B的位置, 在洞里面可以瞬间移动,在洞外面的移动速度为10秒一个单位,求最短时间 看到n<=100,又是求最短时间,想到 ...
- UVA - 1001 Say Cheese(奶酪里的老鼠)(flod)
题意:无限大的奶酪里有n(0<=n<=100)个球形的洞.你的任务是帮助小老鼠A用最短的时间到达小老鼠O所在位置.奶酪里的移动速度为10秒一个单位,但是在洞里可以瞬间移动.洞和洞可以相交. ...
- UVa 1001 奶酪里的老鼠(Dijkstra或Floyd)
https://vjudge.net/problem/UVA-1001 题意:一个奶酪里有n个洞,老鼠在奶酪里的移动速度为10秒一个单位,但是在洞里可以瞬间移动.计算出老鼠从A点到达O点所需的最短时间 ...
- uva 1001(最短路)
题意:在一个三维的奶酪里面有n(n<=100)个洞,老鼠A想到达老鼠B的位置,在洞里面可以瞬间移动,在洞外面的移动速度为10秒一个单位,求最短时间 题解:如果两个洞相交,那么d[i][j]=0: ...
- UVa 10801 Lift Hopping (Dijkstra)
题意:有一栋100层的大楼(标号为0~99),里面有n个电梯(不超过5个),以及要到达的层数(aid),然后是每个电梯走一层所需的时间, 再n行就是对应每个电梯可以到达的层数,数量不定.然后每装换一次 ...
- UVA 11367 - Full Tank? dijkstra+DP
传送门:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 11374 - Airport Express ( dijkstra预处理 )
起点和终点各做一次单源最短路, d1[i], d2[i]分别代表起点到i点的最短路和终点到i点的最短路,枚举商业线车票cost(a, b); ans = min( d1[a] + cost(a, b ...
随机推荐
- nanoporetech/nanonet
nanoporetech/nanonet CodeIssues 7Pull requests 0Projects 0Wiki Insights First generation RNN baseca ...
- inception安装步骤---自己整理的安装步骤
inception安装步骤---自己整理的安装步骤2015-09-18 15:51 6185人阅读 评论(1) 收藏 举报 分类: inception相关版权声明:本文为博主原创文章,未经博主允许不得 ...
- 关于input:-webkit-autofill样式问题
最近在整理项目的时候,遇到了一个chrome浏览器自动填充的样式问题, 用户名跟密码的input都设置为透明颜色,但是会变成黄色,打开chrome调试工具,发现有个input:-webkit-auto ...
- 关于erlang反编译的东西
在查阅了相关文档,想了解erlang反编译的东西.当然,源码可以打包成可以获取源码的,也可以保护源码的. 在ebin下,如果没有或者找不到源码,可以进行反编译,由beam文件得到erl文件. 可以通过 ...
- linux 查找最后几条数据
tail(选项)(参数) -n<N>或——line=<N>:输出文件的尾部N(N位数字)行内容. 例如:grep 查询 2018-02-*/*.log |tail -n 5查询 ...
- IOS8 UIAlertController 弹框
本文转载至 http://blog.csdn.net/jinkaiouyang/article/details/35551769 IOS8中,Apple将UIActionSheet和UIAlertVi ...
- jquery ui 怎么实现tab标签切换效果
1.效果图 2.HTML 代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> &l ...
- call by value reference name
按名调用 Algol 按值调用 Java https://docs.python.org/3.6/faq/programming.html#how-do-i-write-a-function-with ...
- 简单监控网站访问是否正常的shell脚本,邮件报警。网站恢复后继续运行。
#!/bin/bash # 使用curl检查网页是否可以正常访问,如果无法访问则发邮件. SITE=crm.bjzgjh.com PROT=80 URL="http://$SITE:$PRO ...
- [Java多线程] volatile 关键字正确使用方法
volatile 变量具有 synchronized 的可见性特性,但是不具备原子特性,即多线程环境中,使用 volatile 关键字的变量仅可以保证不同线程读取变量时,可以读到最新修改的变量值,但是 ...