zoukankan      html  css  js  c++  java
  • SSL 1762——工厂的烦恼

    Description

      某工厂发现厂里的机器在生产产品时要消耗大量的原材料,也就是说,有大量的原材料变成了废物。因此厂里想找出消耗原材料最大的一条生产线路进行改造,以降低成本。厂里的生产线路是一个有向无环网络,有N台机器分别代表网络中的N个结点。弧< I,j >(i < j)表示原材料从机器i传输到机器j的损耗数量。

    Input

    第一行是两个整数N,M(N<=100,M<=1000),分别表示网络的结点个数和弧数。第二行至M+1行,每行三个整数A,B,C,表示弧上的损耗为C。

    Output

    仅一个整数,为损耗最大的线路的损耗量。

    Sample Input

    5 5
    1 2 2
    2 4 9
    1 3 7
    3 4 1
    4 5 6
    Sample Output

    17


    Floyd改进版,将小于号改为大于号


    代码如下:

    var
      a:array [1..100,1..100] of longint;
      f:array [1..100,1..100] of boolean;
      n,m,max:longint;
    procedure init;
    var
      i,j,x,y,z:longint;
    begin
     readln(n,m);
     max:=0;
     for i:=1 to m do
       begin
         read(x,y,z);
         a[x,y]:=z;
         f[x,y]:=true;
         if z>max then max:=z;
       end;
    end;
    
    procedure main;
    var
      i,j,k:longint;
    begin
      for k:=1 to n do
        for i:=1 to n do
          for j:=1 to n do
            if (k<>i) and (k<>j) and (i<>j) and (f[i,k]) and (f[k,j]) then
              if a[i,k]+a[k,j]>a[i,j] then
                begin
                  a[i,j]:=a[i,k]+a[k,j];
                  f[i,j]:=true;
                  if a[i,j]>max then max:=a[i,j];
                end;
      write(max);
    end;
    
    begin
      init;
      main;
    end.
  • 相关阅读:
    46 Simple Python Exercises-Higher order functions and list comprehensions
    IDEA一些设置
    DDD建模案例----“视频课程”场景
    LA 4727
    uva 1377
    uva 1421
    UVA
    LA 4731
    uva 11404
    uva 11143
  • 原文地址:https://www.cnblogs.com/Comfortable/p/8412331.html
Copyright © 2011-2022 走看看