UVa10803_Thunder Mountain(最短路)(小白书图论专题)
来源:互联网 发布:linux redis 编辑:程序博客网 时间:2024/05/29 03:26
解题报告
裸floyd。
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#define inf 0x3f3f3f3fusing namespace std;int n;double mmap[210][210];struct node { double x,y;} p[210];double disc(node p1,node p2) { return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}void floyd() { for(int k=0; k<n; k++) for(int i=0; i<n; i++) for(int j=0; j<n; j++) mmap[i][j]=min(mmap[i][j],mmap[i][k]+mmap[k][j]);}int main() { int i,j,t,k=1; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0; i<n; i++) { scanf("%lf%lf",&p[i].x,&p[i].y); } for(i=0; i<n; i++) { for(j=0; j<n; j++) { double d=disc(p[i],p[j]); if(d<=10) mmap[i][j]=d; else mmap[i][j]=inf; } mmap[i][i]=0; } floyd(); double ans=0; for(i=0; i<n; i++) { for(j=0; j<n; j++) { if(mmap[i][j]>ans) ans=mmap[i][j]; } } printf("Case #%d:\n",k++); if(ans==inf) printf("Send Kurdy\n"); else { printf("%.4lf\n",ans); } printf("\n"); }}
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
Problemsetter: Igor Naverniouk
- UVa10803_Thunder Mountain(最短路)(小白书图论专题)
- UVa567_Risk(最短路)(小白书图论专题)
- UVa558_Wormholes(最短路)(小白书图论专题)
- uva 10803 Thunder Mountain(最短路)
- UVa10048_Audiophobia(最短路/floyd)(小白书图论专题)
- UVa10801_Lift Hopping(最短路)(小白书图论专题)
- UVa10986_Sending email(最短路)(小白书图论专题)
- 最短路专题
- 最短路专题【完结】
- 最短路专题【完结】
- 最短路专题
- 最短路问题专题
- 最短路专题
- 图论 最短路 difjstra 专题
- 图论 最短路 Bellman_Ford 专题
- Kuangbin专题四 最短路
- UVA - 10803 Thunder Mountain 最短路的最大值
- UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)
- 金庸武侠小说之我的见解
- LeetCode—***寻找二叉树中任意两个节点之间的最大值Binary Tree Maximum Path Sum
- poj2373 灌溉草场
- linux上编译mongodb c++ 客户端sdk
- Qt Model/View 学习笔记 (四)
- UVa10803_Thunder Mountain(最短路)(小白书图论专题)
- 单向链表的操作
- 实例学习gcc+gdb+make
- HDOJ 1171 Big Event in HDU(多重背包)
- HDU 1203 I NEED A OFFER!(01背包)
- Qt Model/View 学习笔记 (五)
- Web 服务器错误代码大全(转)
- POJ 1203 I NEED A OFFER!(01背包)
- POJ 2112 Optimal Milking (二分 + floyd + 网络流)