您的位置:首页 > 其它

UVA 1001 Say Cheese

2016-08-10 22:44 309 查看
题目链接  http://acm.hust.edu.cn/vjudge/problem/35891

题意:在一个三维的奶酪里面有n(n<=100)个洞,三维坐标。

老鼠A想到达老鼠B的位置,在洞里面可以瞬间移动,

在洞外面的移动速度为10秒一个单位,求最短时间

计算洞与洞之间的距离

老鼠A和老鼠B所在位置的半径r[0] = r[n+1] = 0;

如果洞i与洞j有相交 mp[i][j] = 0

否则  mp[i][j] = cal(i, j) 看代码

然后就直接Floyd求最短距离了

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#define pi acos(-1)
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int, int> P;
const int maxn = 1e5 + 5;

int x[105], y[105], z[105], r[105], n;
double mp[105][105];
double cal(int a, int b)
{
double xx = x[a] - x[b];
double yy = y[a] - y[b];
double zz = z[a] - z[b];
double d = sqrt(xx*xx + yy*yy + zz*zz) - r[a] - r[b];
if (d < 0) return 0;
return d;
}
int main(void)
{
// freopen("C:\\Users\\wave\\Desktop\\NULL.exe\\NULL\\in.txt","r", stdin);
int i, j, k, cas = 1;
while (cin >> n && n!=-1)
{
for (i = 1; i <= n; i++)
scanf("%d %d %d %d", &x[i], &y[i], &z[i], &r[i]);
scanf("%d %d %d", &x[0], &y[0], &z[0]);
scanf("%d %d %d", &x[n+1], &y[n+1], &z[n+1]);
r[0] = r[n+1] = 0;
for (i = 0; i <= n+1; i++){
for (j = i; j <= n+1; j++){
if (i == j) mp[i][j] = 0;
else mp[i][j] = mp[j][i] = cal(i, j);
}
}
for (k = 0; k <= n+1; k++){
for (i = 0; i <= n+1; i++){
for (j = 0; j <= n+1; j++){
mp[i][j] = min(mp[i][j], mp[i][k] + mp[k][j]);
}
}
}
printf("Cheese %d: Travel time = %.f sec\n", cas++, mp[0][n+1]*10);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: