UVA - 1001 Say Cheese(奶酪里的老鼠)(flod)
题意:无限大的奶酪里有n(0<=n<=100)个球形的洞。你的任务是帮助小老鼠A用最短的时间到达小老鼠O所在位置。奶酪里的移动速度为10秒一个单位,但是在洞里可以瞬间移动。洞和洞可以相交。输入n个球的位置和半径,以及A和O的坐标,求最短时间。
分析:
1、因为洞可以相交,所以在计算两点距离时要判断一下if(dist > num[i].r + num[j].r)。
2、两球间的距离为球心间距离-两球半径,起点和终点不是球,可将半径设为0。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 100 + 10;
const int MAXT = 10000 + 10;
using namespace std;
double d[MAXN][MAXN];
struct Point{
int x, y, z, r;
void read(){
scanf("%d%d%d", &x, &y, &z);
}
}num[MAXN];
double getD(Point &A, Point &B){
return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y) + (A.z - B.z) * (A.z - B.z));
}
int main(){
int n;
int kase = 0;
while(scanf("%d", &n) == 1){
if(n == -1) return 0;
memset(d, 0, sizeof d);
for(int i = 0; i < n; ++i){
num[i].read();
scanf("%d", &num[i].r);
}
num[n].read(), num[n].r = 0;
num[n + 1].read(), num[n + 1].r = 0;
for(int i = 0; i < n + 2; ++i){
for(int j = i + 1; j < n + 2; ++j){
double dist = getD(num[i], num[j]);
if(dist > num[i].r + num[j].r){
d[i][j] = d[j][i] = dist - num[i].r - num[j].r;
}
else{
d[i][j] = d[j][i] = 0;
}
}
}
for(int k = 0; k < n + 2; ++k){
for(int i = 0; i < n + 2; ++i){
for(int j = 0; j < n + 2; ++j){
d[i][j] = Min(d[i][j], d[i][k] + d[k][j]);
}
}
}
printf("Cheese %d: Travel time = %.0lf sec\n", ++kase, d[n][n + 1] * 10);
}
return 0;
}
UVA - 1001 Say Cheese(奶酪里的老鼠)(flod)的更多相关文章
- UVA 1001 Say Cheese 奶酪里的老鼠(最短路,floyd)
题意:一只母老鼠想要找到她的公老鼠玩具(cqww?),而玩具就丢在一个广阔的3维空间(其实可以想象成平面)上某个点,而母老鼠在另一个点,她可以直接走到达玩具的位置,但是耗时是所走过的欧几里得距离*10 ...
- UVa 1001 奶酪里的老鼠(Dijkstra或Floyd)
https://vjudge.net/problem/UVA-1001 题意:一个奶酪里有n个洞,老鼠在奶酪里的移动速度为10秒一个单位,但是在洞里可以瞬间移动.计算出老鼠从A点到达O点所需的最短时间 ...
- UVa 1001 Say Cheese【floyd】
题意:在一个三维的奶酪里面有n(n<=100)个洞,老鼠A想到达老鼠B的位置, 在洞里面可以瞬间移动,在洞外面的移动速度为10秒一个单位,求最短时间 看到n<=100,又是求最短时间,想到 ...
- UVA 1001 Say Cheese
题意: 一只母老鼠想要找到她的玩具,而玩具就丢在一个广阔的3维空间上某个点,而母老鼠在另一个点,她可以直接走到达玩具的位置,但是耗时是所走过的欧几里得距离*10s.还有一种方法,就是靠钻洞,洞是球形的 ...
- UVa 1001 Say Cheese (Dijkstra)
题意:给定一个三维空间的一些球和起始位置和结束位置,问你最短要花的时间是多少. 析:建图,所有的位置都建立图,边权就是距离,最小求一次最短路即可. 代码如下: #pragma comment(link ...
- uva 1001(最短路)
题意:在一个三维的奶酪里面有n(n<=100)个洞,老鼠A想到达老鼠B的位置,在洞里面可以瞬间移动,在洞外面的移动速度为10秒一个单位,求最短时间 题解:如果两个洞相交,那么d[i][j]=0: ...
- UVA 10673 扩展欧几里得
题意:给出x 和k,求解p和q使得等式x = p[x / k] + q [ x / k], 两个[x / k]分别为向下取整和向上取整 题解:扩展欧几里得 //meek///#include<b ...
- 紫书 习题 11-2 UVa 1001 (Floyd)
这道题只是在边上做一些文章. 这道题起点终点可以看成半径为0的洞, 我是直接加入了洞的数组. 边就是两点间的距离减去半径, 如果结果小于0的话, 距离就为0, 距离不能为负 然后我看到n只有100, ...
- Uva1001 Say Cheese Floyd
题意:一个无限大的奶酪里有n个球形的洞,在洞内可以瞬移,不然每一个单位要用10sec,现在给定起始点和结束点,问最短需要耗时多久? 思路:把球形的洞当做是节点,两点之间的距离是两者球心的距离减去两者的 ...
随机推荐
- 有时间会做系列一(Dice)
题目大意:给n个骰子的每面安排点数,第i个骰子有a[i]面,a[i]和为m,点数范围从1到m,不重复.问怎么安排掷骰子的点数和的期望最大.输出期望和每个骰子的点数(按骰子输入顺序). 思路: EX=x ...
- Cadence套件:Capture + Allegro应用笔记
1.在Allegro中导入Netlist时,需要进行封装路径的设定: 在Setup->User Preference的Path->Library下面,设定所需封装文件(psm).焊盘文件( ...
- ie brower 点击用默认浏览器打开链接
<script> function GetCurrentJumpUrl(){ var eleLink = document.getElementById('adLink'); if(ele ...
- JAVA虚拟机:内存回收策略及算法
java虚拟机中的程序计数器区.虚拟机栈区.本地方法栈区3个区域是随着线程的创建而创建,随着线程的结束而结束时,内存自然得到回收,所以这三个区域不需要过多考虑内存的回收问题. java虚拟机中的方法区 ...
- UITree_study
1.Create canvas 2.Add TreeView 3.Subscribe and unsubscribe events(订阅和取消订阅事件) 4.Data bind items it's ...
- HiBench成长笔记——(9) 分析源码monitor.py
monitor.py 是主监控程序,将监控数据写入日志,并统计监控数据生成HTML统计展示页面: #!/usr/bin/env python2 # Licensed to the Apache Sof ...
- Vue - 定义使用组件
import Card from './components/Card.vue' Vue.component('m-card',Card) // component是注册全局组件,在实例化VUE前 ...
- 机器阅读理解(看各类QA模型与花式Attention)(转载)
目录 简介 经典模型概述 Model 1: Attentive Reader and Impatient Reader Attentive Reader Impatient Reader Model ...
- Minikube安装
参考 https://blog.csdn.net/liumiaocn/article/details/52041726?locationNum=4&fps=1 中文社区API http://d ...
- Git内部原理探索
目录 前言 Git分区 .git版本库里的文件/目录是干什么的 Git是如何存储文件信息的 当我们执行git add.git commit时,Git背后做了什么 Git分支的本质是什么 HEAD引用 ...