/ Vijos / 题库 / 海战 /

题解

122 条题解

  • 0
    @ 2009-04-07 18:16:29

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    var r,c,x,y,s:integer;

    a:array[0..1001,0..1001] of char;

    i,j,xx,yy,p,q,k,l:integer;

    begin

    readln(r,c);

    s:=0;

    for x:= 1 to r do

    begin

    for y:= 1 to c do

    read(a[x,y]);

    readln;

    end;

    for x:= 1 to r do

    for y:= 1 to c do

    if a[x,y] = '#' then

    begin

    if (( a[x-1,y] = '.') and ( a[x+1,y] = '.') and (a[x,y-1]='.') and (a[x,y+1]='.')) then

    begin

    inc(s);

    a[x,y]:='.';

    end

    else

    begin

    i:=0;

    j:=0;

    xx:=x;

    yy:=y;

    while a[xx,yy] = '#' do

    begin

    inc(i);

    inc(yy);

    end;

    xx:=x;

    yy:=y;

    while a[xx,yy] = '#' do

    begin

    inc(j);

    inc(xx);

    end;

    xx:=x;

    yy:=y;

    for p:= x to x + j - 1 do

    if (a[p,y+i] = '#') then

    begin

    writeln('Bad placement.');

    halt;

    end;

    for p:= x+1 to x + j - 1 do

    if a[p,y-1] = '#' then

    begin

    writeln('Bad placement.');

    halt;

    end;

    for p:= y to y + i - 1 do

    if a[x+j,p] = '#' then

    begin

    writeln('Bad placement.');

    halt;

    end;

    for p:= x to x + j - 1 do

    for q:= y to y + i - 1 do

    if a[p,q] '#' then

    begin

    writeln('Bad placement.');

    halt;

    end;

    for p:= x to x+j-1 do

    for q:= y to y+i-1 do

    a[p,q]:='.';

    inc(s);

    end;

    end;

    writeln('There are ',s,' ships.');

    end.

    猥琐的解法

  • 0
    @ 2009-02-27 22:39:26

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    var a:array[0..1001,0..1001]of char;

    b:array[1..1000,1..1000]of integer;

    i,j,n,m,k,x,y,i1,j1:integer;

    o:boolean;

    function fx(i,j:integer):integer;

    var x:integer;

    begin

    x:=i;

    while a[x,j]='#' do inc(x);

    exit(x-1);

    end;

    function fy(i,j:integer):integer;

    var y:integer;

    begin

    y:=j;

    while a='#' do inc(y);

    exit(y-1);

    end;

    procedure fill(i,j,x,y,k:integer);

    var i1,j1:integer;

    begin

    for i1:=i to x do

    for j1:=j to y do

    b[i1,j1]:=k;

    end;

    begin

    readln(n,m);

    for i:=1 to n do

    begin

    for j:=1 to m do read(a);

    readln;

    end;

    k:=0;

    for i:=1 to n do

    for j:=1 to m do

    if (a='#') and (b=0) then

    begin

    o:=true;

    x:=fx(i,j);

    y:=fy(i,j);

    for i1:=i to x do

    for j1:=j to y do

    if a[i1,j1]='.' then o:=false;

    for i1:=i to x do

    begin

    if a[i1,j-1]='#' then o:=false;

    if a[i1,y+1]='#' then o:=false;

    end;

    for j1:=j to y do

    begin

    if a='#' then o:=false;

    if a[x+1,j1]='#' then o:=false;

    end;

    if o then

    begin

    inc(k);

    fill(i,j,x,y,k);

    end

    else

    begin

    writeln('Bad placement.');

    exit;

    end;

    end;

    writeln('There are ',k,' ships.');

    end.

    简单floodfill

  • 0
    @ 2009-02-17 23:04:44

    有种莫名的冲动...

    if(s>1)cout

  • 0
    @ 2009-02-14 20:37:19

    其实就很简单一道搜索题,DFS,BFS,Floodfill……

    这题我一开始连输入都读错了还能过5个点,o(╯□╰)o

  • 0
    @ 2009-01-21 17:25:20

    其实就很简单的一道搜索题

  • 0
    @ 2008-12-20 14:15:12

    好奇怪,参看了 [blue]自由狂想论[/blue] 的题解

    检查了**是否方形周围都为海**,就[red]**AC**[/red]了

    但这样的话如下的情况便只能输出"There are 1 ships."

    是否不符题意呢?还是说斜着的算一条?

    3 3 # . . . # . . . #

  • 0
    @ 2008-12-06 16:11:00

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    用搜索过的...

  • 0
    @ 2008-11-13 08:51:57

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    考前做水题。

  • 0
    @ 2008-11-07 12:11:44

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    floodfill,加{判断 核心代码}:

    if ((map=1) and (map=1) and (map=1) and (map=0))

    or ((map=1) and (map=1) and (map=0) and (map=1))

    or ((map=1) and (map=0) and (map=1) and (map=1))

    or ((map=0) and (map=1) and (map=1) and (map=1))

  • 0
    @ 2008-11-03 10:48:16

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    procedure floodfill(x,y:longint);//uncompleted

    var t:longint;

    begin

    if x>mx then mx:=x;

    if y>my then my:=y;

    if x

  • 0
    @ 2008-10-31 08:51:09

    格式错误的人注意了.

    Bad placement. 后面有个'.'

    There are X ships. 后面也要一个'.'

  • 0
    @ 2008-10-29 20:03:01

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    直接BFS,直接秒杀!

  • 0
    @ 2008-10-27 13:29:39

    恶心啊....第一次交的时候打错一个地方竟然得了90分.....

  • 0
    @ 2008-10-18 20:23:31

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 384ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:384ms

    貌似数据弱

    我枚举的

  • 0
    @ 2008-10-09 19:39:08

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2008-10-09 18:46:14

    谁能告诉我‘格式错误’是咋的回事啊!!!!!!

  • 0
    @ 2008-10-07 21:32:03

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 134ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:134ms

    真没想到能一次AC!太激动了!

    o(≧v≦)o

  • 0
    @ 2008-09-27 12:28:42

    由于c,r

  • 0
    @ 2008-09-20 09:28:50

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2008-09-17 23:06:02

    晕 两句都有句点 思维定势 没看见 debug了半天

信息

ID
1076
难度
5
分类
搜索 | 搜索与剪枝 点击显示
标签
(无)
递交数
3107
已通过
1032
通过率
33%
被复制
10
上传者