zoukankan      html  css  js  c++  java
  • poj2253

    dijkstra

    把存最短距离的数组改为存储frog distance即可

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <cmath>
    using namespace std;
    
    const int maxn = 201, inf = 1000000000;
    
    struct point
    {
    	int x, y;
    } stone[maxn];
    
    int n;
    double dist[maxn];
    bool vis[maxn];
    
    void init()
    {
    	for (int i = 0; i < n; i++)
    		scanf("%d%d", &stone[i].x, &stone[i].y);
    }
    
    double distan(point &a, point &b)
    {
    	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
    }
    
    void dijkstra()
    {
    	double best = 0;
    	int besti = 0;
    
    	for (int i = 0; i < n; i++)
    		dist[i] = inf;
    	memset(vis, 0, sizeof(vis));
    	vis[0] = true;
    	dist[0] = 0;
    	while (besti != -1 && !vis[1])
    	{
    		for (int i = 0; i < n; i++)
    		{
    			double temp = max(dist[besti], distan(stone[i], stone[besti]));
    			if (dist[i] > temp)
    				dist[i] = temp;
    		}
    		best = inf;
    		besti = -1;
    		for (int i = 0; i < n; i++)
    			if (!vis[i] && dist[i] < best)
    			{
    				best = dist[i];
    				besti = i;
    			}
    		vis[besti] = true;
    	}
    }
    
    int main()
    {
    	//freopen("D:\\t.txt", "r", stdin);
    	int t = 0;
    	while (scanf("%d", &n) != EOF && n != 0)
    	{
    		init();
    		dijkstra();
    		t++;
    		printf("Scenario #%d\nFrog Distance = %.3f\n\n", t, dist[1]);
    	}
    	return 0;
    }
  • 相关阅读:
    计算机语言发展简史
    HTML—xhtml和html5
    网络协议模型【简图】
    http协议
    URL简介
    TCP协议简介
    比较浏览器的“刷新”
    loadrunner之运行方式:线程还是进程?
    LoadRunner的函数
    LoadRunner测试结果分析
  • 原文地址:https://www.cnblogs.com/rainydays/p/1948668.html
Copyright © 2011-2022 走看看