/ Vijos / 题库 / 海战 /

题解

122 条题解

  • 0
    @ 2009-09-08 16:09:57

    英语 阿 ~~~~

    我把 are打成 is了

    附判断的程序:

    bool check(int i ,int j)

    {

    if(f[i][j] == 0)

    {

    if(i>1&&j>1 && f[i][j-1]==-1&& f[j]==-1&&f[j-1]!=0) badp = true;

    else if(i>1&&j

  • 0
    @ 2009-09-03 21:27:30

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    汗。。第一次提交直接输出了ANS没句子 20分。后来改了就AC~~

    先检查有无BAD方法是搜索每一个2*2的方形查找正好有3个'#'的

    然后利用预处理的SUM来找船个数~

  • 0
    @ 2009-08-27 15:04:14

    program meisilu;

    var

    max,a,b,c,d,e,f,ak,ka:longint;

    xx:array[1..1000,1..1000] of longint;

    yy:array[1..1000,1..1000] of longint;

    s:char;

    begin

    readln(ak,ka);

    for a:=1 to ak do

    begin

    for b:=1 to ka do

    begin

    read(s);

    if s='#' then begin

    xx[a,b]:=1; yy[a,b]:=1;

    if (a=1) and (b1) then

    if (xx[a,b-1]0) and (yy[a,b-1]0) then

    xx[a,b]:=xx[a,b-1]+1;

    if (a1) and (b=1) then

    if (xx[a-1,b]0) and (yy[a-1,b]0) then

    yy[a,b]:=yy[a-1,b]+1;

    if (a1) and (b1) then

    begin

    if (xx[a-1,b]0) and (xx[a,b-1]0) then

    if (xx[a-1,b]-xx[a,b-1]1) or (yy[a,b-1]-yy[a-1,b]1) then

    begin

    writeln('Bad placement.');

    exit;

    end;

    if (xx[a-1,b]>1) and (xx[a,b-1]=0) then

    begin

    writeln('Bad placement.');

    exit;

    end;

    if (xx[a-1,b]=0) and (yy[a,b-1]>1) then

    begin

    writeln('Bad placement.');

    exit;

    end;

    if xx[a-1,b]0 then

    xx[a,b]:=xx[a-1,b];

    if yy[a,b-1]0 then

    yy[a,b]:=yy[a,b-1];

    if yy[a,b-1]=0 then yy[a,b]:=yy[a-1,b]+1;

    if yy[a-1,b]=0 then xx[a,b]:=xx[a,b-1]+1;

    end;

    end;

    end;

    readln;

    end;

    for a:=1 to ak do

    for b:=1 to ka do

    begin

    if (xx[a,b]0) and (yy[a,b]0) then begin

    if (a=ak) and (bka) then

    if (xx[a,b]0) and (xx[a,b+1]=0) then inc(max);

    if (aak) and (b=ka) then

    if (yy[a+1,b]=0) and (yy[a,b]0) then inc(max);

    if (a=ak) and (b=ka) and (yy[a,b]0) then inc(max);

    if (aak) and (bka) then

    if (xx[a+1,b]=0) and (xx[a,b+1]=0) and (xx[a,b]0)

    then inc(max);

    end;

    end;

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

    end.

    怎么就我一个人还傻的用动规做这个题,郁闷

  • 0
    @ 2009-08-27 15:02:30

    floodfill

    program ballte;

    var i,j,k,l,m,n,r,c,sum:longint; qq:boolean;

    a:Array[0..1000,0..1000] of char;

    procedure dfs(m,n:longint);

    var i,j,k,l,x,y:longint;

    begin

    k:=1; if a[m+k,n]='#' then

    while a[m+k,n]='#' do

    inc(k)

    else k:=1;

    x:=k-1;

    if a[m+x+1,n]='?' then

    begin

    qq:=false;

    exit;

    end;

    k:=1; if a[m,n+k]='#' then

    while a[m,n+k]='#' do

    inc(k)

    else k:=1;

    y:=k-1;

    if a[m,n+y+1]='?' then

    begin

    qq:=false;

    exit;

    end;

    for i:=m to m+x do

    for j:=n to n+y do

    begin

    if a='.' then

    begin

    qq:=false;

    exit;

    end;

    if a='#' then

    a:='?';

    end;

    inc(sum);

    end;

    begin

    readln(r,c);

    qq:=true;

    for i:=1 to r do

    begin

    for j:=1 to c do

    read(a);

    readln;

    end;

    for i:=1 to r do

    for j:=1 to c do

    begin

    if a='#' then

    dfs(i,j);

    if qq=false then

    begin

    writeln('Bad placement.');

    exit;

    end;

    end;

    write('There are ');

    write(sum);

    writeln(' ships.');

    end.

  • 0
    @ 2009-08-24 17:07:48

    ....-.-

    忘了输出格式“There are S ships.”

    害的我交N次....

  • 0
    @ 2009-08-20 17:40:48

    有点水。。。

  • 0
    @ 2009-08-19 20:11:15

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    朴素的DFS。

  • 0
    @ 2009-08-09 12:57:04

    如对本题有疑问可以参看我的题解:http://xujieqi.blog.hexun.com/35722312_d.html

  • 0
    @ 2009-08-06 00:01:43

    1.找出一整条船后再淹没,因为中途要判断是否接触.

    2.若任意一个边长为2的小正方形中有3个格为'#',1个格为'.', 那么输出'Bad placement.'

  • 0
    @ 2009-08-03 11:29:51

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    一次秒杀...

    还是觉得这道题目的测试数据有点弱

    我的优化只优化了一半 就交上去 都能秒杀 ⊙﹏⊙b汗

  • 0
    @ 2009-07-30 14:40:29

    ★ 一次AC ~~☆

    条件比较死

    没什么BT的地方

    判断和注意一下搜索与修改就行了

  • 0
    @ 2009-07-27 21:45:15

    记录号 Flag 得分 记录信息 环境 评测机 程序提交时间

    R1359025 Accepted 100 From RayXie-

      P1076 FPC Vivid Puppy 2009-7-27 21:44:06

    From cqwshll

    海战

    编译通过...

    ├ 测试数据 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[1..1000,1..1000]of char;

    ans:longint;

    hang,lie:integer;

    procedure init;

    var

    i,j:integer;

    begin

    readln(hang,lie);

    for i:=1 to hang do

    begin

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

    readln;

    end;

    end;

    function check:boolean;

    var

    i,j:integer;

    begin

    check:=true;

    for i:=1 to hang-1 do

    for j:=1 to lie-1 do

    if ((a='#')and(a='#')and((aa)or(aa)))

    or((a='#')and(a='#')and((aa)or(aa))) then

    begin

    check:=false;

    exit;

    end;

    end;

    procedure work;

    var

    i,j,k,l,m,n:integer;

    hi,hj,ti,tj:integer;

    begin

    for i:=1 to hang do

    for j:=1 to lie do

    if a='#'then

    begin

    hi:=i;

    hj:=j;

    m:=i;

    n:=j;

    while a[m,n]='#' do inc(n);

    dec(n);

    while a[m,n]='#' do inc(m);

    dec(m);

    ti:=m;

    tj:=n;

    for k:=hi to ti do

    for l:=hj to tj do

    a[k,l]:='.';

    inc(ans);

    end;

    end;

    begin

    init;

    ans:=0;

    if check then begin work;writeln('There are ',ans,' ships.');end

    else writeln('Bad placement.');

    end.

  • 0
    @ 2009-07-23 21:37:01

    其实不符合的情况只要用这种方法判断就行了:

    # ## ##

    ## # #

    只要出现这4种图形中的一种就可以说是Bad Placement.

    至于剩下的直接就DFS一遍轻松解决了.

  • 0
    @ 2009-07-18 09:47:05

    好爽,今天做的第一道就一次AC~~庆祝一下

    方法:

    1.找矩阵边界

    2.查找内部是否符合

    3.查找外部是否符合

    4.符合:清空矩阵,即将其淹没

    不符合:推出相撞,退出

    很轻松,纯搜索

    AC+0MS

  • 0
    @ 2009-07-18 08:16:00

    Star_Psy和visister的判断Bad Placement的方法好像有问题:

    注意这样的摆放:

    .......***|\**|*

    ***|\
    **|\**|\**|**

    ***|\**|*.......

    或者:

    ***|\
    **|*.......

    ***|\**|\**|\**|*

    .......***|\***|*

    大家看看是不是可能有问题?

    如果错了,请PM我……

  • 0
    @ 2009-06-15 14:25:07

    s=1 时

    也要输出'There are 1 ships.' ??

  • 0
    @ 2009-06-01 13:00:20

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

    i,j,k,l,m,n,q,w,e,r,s,d,z,x,c:longint;

    procedure f(q,w:longint);

    begin

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

    if a[q+1,w]='#' then f(q+1,w);

    if a[q-1,w]='#' then f(q-1,w);

    if a[q,w+1]='#' then f(q,w+1);

    if a[q,w-1]='#' then f(q,w-1);

    end;

    begin

    readln(r,c);

    for i:=1 to r do

    begin

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

    readln;

    end;

    for i:=1 to r do

    for j:=1 to c do

    if ((a='#') and (a='#') and (a='#') and (a='.'))

    or ((a='#') and (a='.') and (a='#') and (a='#'))

    or ((a='#') and (a='#') and (a='.') and (a='#'))

    or ((a='.') and (a='#') and (a='#') and (a='#'))

    then

    begin

    writeln('Bad placement.');

    halt;

    end;

    for i:=1 to r do

    for j:=1 to c do

    if a='#' then

    begin

    f(i,j);

    s:=s+1;

    end;

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

    end.

  • 0
    @ 2009-05-28 18:56:01

    首想广搜

    发现模拟更方便 = =

    ljq的判断相撞的办法我用上了,算是借鉴吧

  • 0
    @ 2009-06-13 12:56:48

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    深搜

    1.判断是否相撞

    若任意一个边长为2的小正方形中有且只有1个格为'.' 那么输出'Bad placement.'

    2.寻找长方形

    先找长:从当前位置向右找出最长只含'#'的边

    再找高:从当前位置向下找出最长只含'#'的边

    把这个范围内的船体用'.'替代

    x增加1

  • 0
    @ 2009-05-15 22:16:47

    Accepted

    通过   777人

    【1】找出有多少块#

    【2】判断是否bad 的方法

    看是否有一个“ . ” 的相邻两个方向有#

    如果有 则是 bad ||

    否则 输出块数 ||

    \/ =========================

    .#

    #.

    #.

    #.

    #

信息

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