• Uva1001-floyd算法-建图


    给出一些球,球内的时间为零,球之间的速度为10每单位。

    给两个点,求最短时间。

    把每一个球当做点,球间的距离就是floyd的d数组。之后跑一遍floyd

    wa了两发因为d数组定义成int了

    #include <algorithm>
    #include <cstring>
    #include <ctype.h>
    #include <cstdlib>
    #include <cstdio>
    #include <vector>
    #include <string>
    #include <queue>
    #include <stack>
    #include <cmath>
    #include <set>
    #include <map>
    
    using namespace std;
    
    const int INF = 100000;
    
    int N,M,T;
    double d[110][110];
    
    struct holes
    {
        int x,y,z;
        int r;
    }hole[110];
    
    double dist(int a,int b)
    {
        double ans =  (sqrt(abs(hole[a].x-hole[b].x)*abs(hole[a].x-hole[b].x)+
                            abs(hole[a].y-hole[b].y)*abs(hole[a].y-hole[b].y)+
                            abs(hole[a].z-hole[b].z)*abs(hole[a].z-hole[b].z)
                        ) - (hole[a].r + hole[b].r)) ;
        return ans > 0 ? ans : 0;
    }
    
    int main()
    {
        while(scanf("%d",&N) && N != -1)
        {
            T++;
            for(int i=0;i<N;i++)
            {
                scanf("%d%d%d%d",&hole[i].x,&hole[i].y,&hole[i].z,&hole[i].r);
            }
            scanf("%d%d%d",&hole[N].x,&hole[N].y,&hole[N].z);
            scanf("%d%d%d",&hole[N+1].x,&hole[N+1].y,&hole[N+1].z);
            hole[N].r = 0;
            hole[N+1].r = 0;
    
            for(int i=0;i<N+2;i++)
                for(int j=0;j<N+2;j++)
                    d[i][j] = (i==j ? 0 : INF);
    
            for(int i=0;i<N+2;i++)
                for(int j=0;j<N+2;j++)
                {
                    if(i != j) d[i][j] = dist(i,j);
                }
    
            for(int k=0;k<N+2;k++)
                for(int i=0;i<N+2;i++)
                    for(int j=0;j<N+2;j++)
                        d[i][j] = min(d[i][j] , d[i][k]+d[k][j]);
    
            d[N][N+1]*=10;
            int ans = (d[N][N+1]-(int)d[N][N+1]) < (((int)d[N][N+1]+1)-d[N][N+1]) ? (int)d[N][N+1] : (int)d[N][N+1]+1;
            printf("Cheese %d: Travel time = %d sec
    ",T,ans);
        }    
    }
  • 相关阅读:
    这就是搜索引擎--读书笔记六--索引的查询
    这就是搜索引擎--读书笔记五--索引的建立与更新
    JavaWeb学习总结第四篇--Servlet开发
    算法帝国--读书笔记
    这就是搜索引擎--读书笔记四--索引基础
    这就是搜索引擎--读书笔记三
    Python学习总结之五 -- 入门函数式编程
    ASP.NET-FineUI开发实践-4(二)
    ASP.NET-FineUI开发实践-4
    ASP.NET-FineUI开发实践-3
  • 原文地址:https://www.cnblogs.com/helica/p/4892391.html
Copyright © 2020-2023  润新知