Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.17 KB | None | 0 0
  1. const
  2.   VELOCITY = 10;
  3.  
  4. var
  5.   N, K, i, j: integer;
  6.   f1, f2: text;
  7.   a: Array [0..11, 0..10001] of integer;
  8.   b: Array [0..11, 0..10001] of double;
  9.   minValue: double;
  10.  
  11. begin
  12.   assign(f1, 'input.txt');
  13.   reset(f1);
  14.   assign(f2, 'output.txt');
  15.   rewrite(f2);
  16.   read(f1, N, K);
  17.   readln(f1);
  18.   for i:=0 to 11 do
  19.     for j:=0 to 10001 do
  20.       b[i,j]:=10*10000;
  21.   i:=0;
  22.   try
  23.   while (Not Eof(f1)) do
  24.   begin
  25.     i+=1;
  26.     j:=0;
  27.     while (Not Eoln(f1)) do
  28.     begin
  29.       j+=1;
  30.       read(f1,a[i,j]);
  31.     end;
  32.     readln(f1);
  33.   end;
  34.   except
  35.     exit;
  36.   end;  
  37.    
  38.  
  39.   for i := 1 to N do
  40.   begin
  41.     b[i, 1] := VELOCITY / a[i, 1];
  42.   end;
  43.  
  44.  
  45.   for i := 2 to K do
  46.   begin
  47.     for j := 1 to N do
  48.     begin
  49.       b[j, i] := VELOCITY / a[j, i] + b[j, i - 1];
  50.       if (j - 1) > 0 then
  51.         b[j, i] := min(b[j, i], VELOCITY / a[j, i] + b[j - 1, i - 1]);
  52.       if (j + 1) <= N then
  53.         b[j, i] := min(b[j, i], VELOCITY / a[j, i] + b[j + 1, i - 1]);
  54.     end;
  55.   end;
  56.  
  57.   minValue := b[1, k];
  58.   for j := 2 to n do
  59.     if (b[j, k] < minValue) then
  60.       minValue := b[j, k];
  61.   write(f2, minValue:0:3);
  62.   close(f1);
  63.   close(f2);
  64. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement