UVA 10803 - Thunder Mountain(floyd)
来源:互联网 发布:windows引导命令 编辑:程序博客网 时间:2024/06/05 09:50
Thunder Mountain
Time Limit: 3 seconds
people got flashlights, and some people got
batteries. These guys had all three."J. Michael Straczynski, "Jeremiah."
Markus is building an army to fight the evil Valhalla Sector, so he needs to move some supplies between several of the nearby towns. The woods are full of robbers and other unfriendly folk, so it's dangerous to travel far. As Thunder Mountain's head of security, Lee thinks that it is unsafe to carry supplies for more than 10km without visiting a town. Markus wants to know how far one would need to travel to get from one town to another in the worst case.
Input
The first line of input gives the number of cases, N. N test cases follow. Each one starts with a line containing n (the number of towns, 1<n<101). The next n lines will give the xy-locations of each town in km (integers in the range [0, 1023]). Assume that the Earth is flat and the whole 1024x1024 grid is covered by a forest with roads connecting each pair of towns that are no further than 10km away from each other.
Output
For each test case, output the line "Case #x:", where x is the number of the test case. On the next line, print the maximum distance one has to travel from town A to town B (for some A and B). Round the answer to 4 decimal places. Every answer will obey the formula
fabs(ans*1e4 - floor(ans*1e4) - 0.5) > 1e-2
If it is impossible to get from some town to some other town, print "Send Kurdy" instead. Put an empty line after each test case.Sample InputSample Output
250 010 010 1013 1013 1420 010 1
Case #1:25.0000Case #2:Send Kurdy
题意:n个点,点到点距离大于10的不能走,求所有点到点距离中最大的距离,如果没有可以走的输出Send Kurdy
思路:floyd
代码:
#include <stdio.h>#include <string.h>#include <math.h>#define max(a,b) (a)>(b)?(a):(b)#define min(a,b) (a)<(b)?(a):(b)const int N = 105;const double INF = 1000000000;int t, n, cas = 0;double x[N], y[N], f[N][N];double dis(int i, int j) { return sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));}void init() { scanf("%d", &n); for (int i = 0; i < n; i++)scanf("%lf%lf", &x[i], &y[i]); for (int i = 0; i < n; i ++)for (int j = i; j < n; j++) { f[i][j] = f[j][i] = dis(i, j); if (f[i][j] - 10.0 > 1e-4)f[i][j] = f[j][i] = INF;}}void floyd() { for (int k = 0; k < n; k ++)for (int i = 0; i < n; i ++) for (int j = 0; j < n; j ++) {f[i][j] = min(f[i][k] + f[k][j], f[i][j]); }}void solve() { init(); floyd(); double ans = 0; for (int i = 0; i < n; i ++)for (int j = 0; j < n; j ++) if (i != j)ans = max(ans, f[i][j]); printf("Case #%d:\n", ++cas); if (fabs(ans - INF) < 1e-4)printf("Send Kurdy\n"); elseprintf("%.4lf\n", ans); printf("\n");}int main() { scanf("%d", &t); while (t --) {solve(); } return 0;}
- UVA 10803 - Thunder Mountain(floyd)
- uva 10803 Thunder Mountain (floyd)
- Thunder Mountain - UVa 10803 Floyd
- UVa:10803 Thunder Mountain(floyd求多源最短路)
- uva 10803 - Thunder Mountain
- UVA - 10803 Thunder Mountain
- UVa 10803 - Thunder Mountain
- uva 10803Thunder Mountain
- uva 10803 Thunder Mountain(最短路)
- UVa 10803 Thunder Mountain (任意两点最短路的最大值+Floyd)
- 10803 - Thunder Mountain
- UVA - 10803 Thunder Mountain 最短路的最大值
- Thunder Mountain
- UVa10803 - Thunder Mountain
- uva 12222 - Mountain Road(dp+贪心)
- UVA 12222 Mountain Road
- Mountain Road UVA
- uva 10122 Mysterious Mountain and ZOJ 1231 Mysterious Mountain (二分+二部图最大匹配)
- [codility]Tree-height
- 程控交换课外实习报告
- Android 的 init.rc 文件简介
- OpenRisc-58-ORPSoC调试环境的构建
- [codility]Prefix-set
- UVA 10803 - Thunder Mountain(floyd)
- [codility]Array-inversion-count
- 时分复用
- LeetCode Letter Combinations of a Phone Number 经典组合问题
- Linux input子系统分析 事件处理层分析
- [codility]Falling-discs
- 敏捷的商业价值是什么,与传统对比的特点是什么?
- Android源码开发环境搭建
- 鞋