|  | 
|  | 
| вернуться в форум | Statement of this problem is not very clear, isn't it? At first: what boundings for sizes of already placed ships?Can it be 0 or greater than 5?
 
 At second: my solution is not very fast and based on small size and
 quantity of already placed ships. Idea is simple: i have two arrays
 for verticals and horizontals and sets true if vertical or horizontal
 is empty and false otherwise. Then i look for all verticals and
 horizontals, trying locate vertical ship in all verticals and
 horizontal ship in all horizontals ( if number of decks of placing
 ship is 1 then i divide output value by 2 ). If current vertical
 (horizontal) line is empty, i just increment total value by "n-
 k+1"("m-k+1"), otherwise use full enumeration for line.
 
 I can predict TL, but always got a WA... =(
 I searched for bug many times and conclused, that i have bug in
 understanding statement of problem. Thank you for reading that.
 Could anyone help me? =)
 
 Code below:
 
 {$APPTYPE CONSOLE}
 var
 cur, i, j, n, m, l, k, r: longint;
 ships: array[1..100] of
 record
 x, y, d: longint;
 o: char;
 end;
 st: string;
 total: extended;
 curline, vempty, hempty: array[0..30001] of boolean;
 {}
 begin
 {  assign( input, 'p1212.in' ); reset( input );
 assign( output, 'p1212.out' ); rewrite( output );}
 {}
 readln( n, m, l );
 for i := 1 to l do
 begin
 read( ships[i].x, ships[i].y, ships[i].d );
 readln( st );
 if ( ( pos( 'V', st ) = 0 ) and ( pos( 'v', st ) = 0 ) ) then
 ships[i].o := 'H'
 else
 ships[i].o := 'V';
 end;
 read( k );
 {}
 for i := 0 to 30001 do
 begin
 curline[i] := true;
 vempty[i] := true;
 hempty[i] := true;
 end;
 {}
 for i := 1 to l do
 begin
 case ( ships[i].o ) of
 'V':
 begin
 for j := ( ships[i].y - 1 ) to ( ships[i].y + ships
 [i].d ) do
 hempty[j] := false;
 vempty[ships[i].x - 1] := false;
 vempty[ships[i].x] := false;
 vempty[ships[i].x + 1] := false;
 end;
 'H':
 begin
 for j := ( ships[i].x - 1 ) to ( ships[i].x + ships
 [i].d ) do
 vempty[j] := false;
 hempty[ships[i].y - 1] := false;
 hempty[ships[i].y] := false;
 hempty[ships[i].y + 1] := false;
 end;
 end;
 end;
 {}
 total := 0;
 {}
 for i := 1 to n do
 begin
 if ( hempty[i] ) then
 total := total + m - k + 1
 else
 begin
 for j := 0 to 30001 do
 curline[j] := true;
 curline[0] := false;
 curline[m+1] := false;
 for j := 1 to l do
 begin
 case ( ships[j].o ) of
 'V':
 begin
 if ( ( ships[j].y - 1 <= i ) and ( ( ships[j].y +
 ships[j].d ) >= i ) ) then
 begin
 curline[ships[j].x-1] := false;
 curline[ships[j].x] := false;
 curline[ships[j].x+1] := false;
 end;
 end;
 'H':
 begin
 if ( ( ( ships[j].y - 1 ) = i ) or ( ( ships
 [j].y ) = i ) or ( ( ships[j].y + 1 ) = i ) ) then
 for r := ( ships[j].x - 1 ) to ( ships[j].x +
 ships[j].d ) do
 curline[r] := false;
 end;
 end;
 end;
 {}
 cur := 0;
 for j := 1 to ( m + 1 ) do
 if ( curline[j] ) then
 inc( cur )
 else
 begin
 if ( cur >= k ) then
 total := total + cur - k + 1;
 cur := 0;
 end;
 end;
 end;
 {}
 for i := 1 to m do
 begin
 if ( vempty[i] ) then
 total := total + n - k
 | 
 | 
|