http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=963&pid=1019&ojid=1
2011-11-04 13:19
525 查看
这一题是dijstra的变种,,,用的是dijstra的思想和方法,让求的是从一点到另一点的最大的最小值,,,,一开始木有认真读题,,,贡献了5次wa,,,
#include <iostream> #include <cmath> #include<cstdio> using namespace std; #define MAX 201 #define INF 10000.0f float matrix[MAX][MAX]; int s[MAX]; float dis[MAX]; typedef struct point { int x; int y; }point; void Dijkstra(int &n) { int now=1; for(int i = 1; i <= n; ++i) { dis[i] = matrix[now][i]; s[i] = 0; } s[now] = 1; for(int i = 1; i <= n-1; ++i) { float minDis = INF; for(int j = 1; j <= n; ++j) if(!s[j] && dis[j] < minDis) minDis = dis[now=j]; s[now] = 1; for(int j = 1; j <= n; ++j) if(!s[j] && matrix[now][j]!= INF) dis[j] = min(dis[j],max(dis[now],matrix[now][j])); } } int main() { int n; point p[MAX]; int count = 0; while(~scanf("%d",&n)&& n) {for(int i = 1; i <= n; ++i) ~scanf("%d%d", &p[i].x, &p[i].y); for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) if(i!=j) matrix[i][j] = INF; else matrix[i][j] = 0; for(int i = 1; i < n; ++i) for(int j = i+1; j <=n; ++j) matrix[j][i] = matrix[i][j] = sqrt(((float)(p[i].x-p[j].x)*(p[i].x-p[j].x)) + (p[i].y-p[j].y)*(p[i].y-p[j].y)); Dijkstra(n); printf("Scenario #%d\nFrog Distance = %.3f\n\n", ++count, dis[2]); } return 0; }
相关文章推荐
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1004&ojid=1&cid=6866&hide=1&problem=Pro
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=791&pid=1001&ojid=0
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?&&次小生成树
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1004&ojid=2&cid=963&hide=0
- To The Max &&http://acm.hdu.edu.cn/showproblem.php?pid=1081
- 二分查找求函数的区间最小值&&http://acm.hdu.edu.cn/showproblem.php?pid=2899
- 找规律。。&&http://acm.hdu.edu.cn/showproblem.php?pid=1097
- http://acm.hdu.edu.cn/showproblem.php?pid=1020&&encoding
- 站站排(重温儿时的游戏) http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=1573&cid=1211
- find the safest road&&http://acm.hdu.edu.cn/showproblem.php?pid=1596
- 导弹拦截二&&http://acm.hdu.edu.cn/showproblem.php?pid=1257
- Buy the Ticket&&http://acm.hdu.edu.cn/showproblem.php?pid=1133
- http://acm.hdu.edu.cn/showproblem.php?pid=1055&&Color a Tree
- HDU Today&&http://acm.hdu.edu.cn/showproblem.php?pid=2112
- Red and Black&&http://acm.hdu.edu.cn/showproblem.php?pid=1312
- 完数 &&http://acm.hdu.edu.cn/showproblem.php?pid=1406
- Trouble&&http://acm.hdu.edu.cn/showproblem.php?pid=4334
- http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2500&cid=1122
- Quoit Design&&http://acm.hdu.edu.cn/showproblem.php?pid=1007
- A C&&http://acm.hdu.edu.cn/showproblem.php?pid=1570