Guest User

dalex

a guest
Jun 30th, 2011
1,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.54 KB | None | 0 0
  1. const
  2.     eps: double = 1e-9;
  3.  
  4. type
  5.     bottle = record
  6.         i, c1, c2: longint;
  7.         v: double;
  8.     end;
  9.  
  10.     cup = record
  11.         i: longint;
  12.         b: array[1..50] of double;
  13.         v: double;
  14.     end;
  15.  
  16. var
  17.     k, i, j, n, m: longint;
  18.     w, w0: double;
  19.     b: array[1..50] of bottle;
  20.     c: array[1..50] of cup;
  21.     f: boolean;
  22.  
  23. begin
  24.     read(n, w, m);
  25.     if 2 * n < m then begin
  26.         writeln('NO');
  27.         halt;
  28.     end;
  29.     w0 := n * w / m;
  30.     for i := 1 to n do begin
  31.         b[i].i := i;
  32.         b[i].c1 := 0;
  33.         b[i].c2 := 0;
  34.         b[i].v := w;
  35.     end;
  36.     for i := 1 to m do begin
  37.         c[i].i := i;
  38.         c[i].v := 0;
  39.         for j := 1 to n do c[i].b[j] := 0;
  40.     end;
  41.     for k := 1 to 2 * n do begin
  42.         i := (k + 1) div 2;
  43.         if abs(b[i].v) < eps then continue;
  44.         for j := 1 to m do begin
  45.             if abs(c[j].v - w0) < eps then continue;
  46.             if (b[i].c1 = j) or (b[i].c2 = j) then continue;
  47.             if (b[i].c1 <> 0) and (b[i].c2 <> 0) then continue;
  48.             if b[i].c1 = 0 then
  49.                 b[i].c1 := j
  50.             else
  51.                 b[i].c2 := j;
  52.             if b[i].v > w0 - c[j].v + eps then begin
  53.                 b[i].v := b[i].v - (w0 - c[j].v);
  54.                 c[j].b[b[i].i] := w0 - c[j].v;
  55.                 c[j].v := w0;
  56.             end else begin
  57.                 c[j].v := c[j].v + b[i].v;
  58.                 c[j].b[b[i].i] := b[i].v;
  59.                 b[i].v := 0;
  60.             end;
  61.             break;
  62.         end;
  63.     end;
  64.     for i := 1 to m do begin
  65.         if abs(c[i].v - w0) > eps then begin
  66.             writeln('NO');
  67.             halt;
  68.         end;
  69.     end;
  70.     writeln('YES');
  71.     for i := 1 to m do begin
  72.         f := true;
  73.         for j := 1 to n do begin
  74.             if c[i].b[j] > eps then begin
  75.                 if f then f := false else write(' ');
  76.                 write(j, ' ', c[i].b[j]:0:12);
  77.             end;
  78.         end;
  79.         writeln;
  80.     end;
  81. end.
Advertisement
Add Comment
Please, Sign In to add comment