zoukankan      html  css  js  c++  java
  • zoj 1655 Transport Goods

    Transport Goods
    Time Limit: 2 Seconds      Memory Limit: 65536 KB
    
    The HERO country is attacked by other country. The intruder is attacking the capital so other cities must send supports to the capital. There are some roads between the cities and the goods must be transported along the roads.
    
    According the length of a road and the weight of the goods, there will be some cost during transporting. The cost rate of each road is the ratio of the cost to the weight of the goods transporting on the road. It is guaranteed that the cost rate is less than 1.
    
    On the other hand, every city must wait till all the goods arrive, and then transport the arriving goods together with its own goods to the next city. One city can only transport the goods to one city.
    
    Your task is find the maximum weight of goods which can arrive at the capital.
    
    
    Input
    
    There are several cases.
    
    For each case, there are two integers N (2 <= N <= 100) and M in the first line, where N is the number of cities including the capital (the capital is marked by N, and the other cities are marked from 1 to N-1), and M is the number of roads.
    
    Then N-1 lines follow. The i-th (1 <= i <= N - 1) line contains a positive integer (<= 5000) which represents the weight of goods which the i-th city will transport to the capital.
    
    The following M lines represent M roads. There are three numbers A, B, and C in each line which represent that there is a road between city A and city B, and the cost rate of this road is C.
    
    Process to the end of the file.
    
    
    Output
    
    For each case, output in one line the maximum weight which can be transported to the capital, accurate up to 2 demical places.
    
    
    Sample Input
    
    5 6
    10
    10
    10
    10
    1 3 0
    1 4 0
    2 3 0
    2 4 0
    3 5 0
    4 5 0
    
    
    Sample Output
    
    40.00


    求最长路径
    #include <iostream>
    #include <stdio.h>
    #include <queue>
    #include <stack>
    #include <set>
    #include <vector>
    #include <math.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    #define N 102
    int value[N];
    double map[N][N];
    int n;
    bool b[N];
    void dijskla()
    {
        memset(b,0,sizeof(b));
        b[n]=1;
        int t=n;
        int i,k;
        double Max;
        while(--t)
        {
            Max=-1.0;
            for(i=1;i<n;i++)
            if(!b[i]&&Max<map[n][i])
             {
                 Max=map[n][i];
                 k=i;
             }
             if(Max==-1.0) break;//有些点不可达
             b[k]=1;
            for(i=1;i<n;i++)
            if(!b[i]&&map[n][i]<map[n][k]*map[k][i])
             {
                map[n][i]=map[n][k]*map[k][i];
             }
        }
    }
    int main()
    {
        int m;
        int i,j;
        double r;
        while(scanf("%d %d",&n,&m)==2)
        {
            for(i=1;i<=n;i++)
             for(j=1;j<=n;j++)
              map[i][j]=0;
            for(i=1;i<n;i++)
             scanf("%d",&value[i]);
            while(m--)
            {
                scanf("%d %d %lf",&i,&j,&r);
                if(map[i][j]<1.0-r) map[i][j]=map[j][i]=1.0-r;//有重边呀、、、郁闷
            }
            dijskla();
            double ans=0;
            for(i=1;i<n;i++)
             ans+=map[n][i]*value[i];
            printf("%.2lf\n",ans);
        }
        return 0;
    }
     
  • 相关阅读:
    《刀塔传奇》
    SSH端口转发
    objective-c与c++的差异
    mysql 远程连接速度慢的解决方案
    maven
    automapper 自动映射 集成asp.net Core2.1
    swagger 集成asp.net Core2.1
    asp.net Core 跨域配置
    处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
    SharedPreferences
  • 原文地址:https://www.cnblogs.com/372465774y/p/2777568.html
Copyright © 2011-2022 走看看