大榕树——让我们共成长!
大榕树 myDrs.org
您的位置:大榕树 \ 编程       |  Logo语言   |  Pascal语言   |  信息学奥赛   |  高考保送    |  HTML版本
|  信息学奥赛>>网上竞赛>>《神奇国度》参考程序         本站全文搜索: 友情提示:

《神奇国度》参考程序
http://www.mydrs.org  10/10/2002  大榕树


试题: 神奇国度。 (20分)
在一个神奇的国度里,住着许多象和马。但是象和马都是脾气暴躁的动物,他们严禁别人踏入自己的领地。一但有动物找到了合适的并且没有占领的土地,他们就会在那里栖息下来,并且把一定的土地划为己有(当然,土地必须在这个国度内),别的动物就不能到他的领地里来了。
我们可以把这个国度看成是 n*m 的矩阵(1<=n,m<=20)。当象占领(x,y)这个点后,(x+2,y+2)、(x+2,y-2)、(x-2,y+2)、(x-2,y-2)以及他自身所在的点就是他的领地了。当马占领(x,y)这个点后,(x+1,y+1)、(x+1,y-1)、(x-1,y+1)、(x-1,y-1)以及他自身所在的点就是他的领地了。</P><P>试问,这个国度最多能供多少个动物栖息?</P><P>输入格式:n m 1<=n,m<=10 (input2.txt)</P><P>输出格式:S1 (output2.txt)</P><P>例如: 输入 3 3
输出 7</P><P>
{$A+,B-,D-,E+,F-,G+,I-,L+,N+,O-,P+,Q+,R-,S-,T+,V+,X+}
{$M 65520,0,655360}
type
    usetype=array[-1..22,-1..22]of boolean;
var
   n,m:longint;
   use:usetype;
   max,now:longint;
   f:array[0..20]of longint;
   km:array[1..20,1..20]of longint;
procedure init;
begin
     assign(input,'input2.txt');
     reset(input);
     read(n,m);
     close(input);
     fillchar(use,sizeof(use),0);
end;
function can(x,y,j:longint):boolean;
begin
     if (use[x+j,y+j])and(x+j<=n)and(y+j<=m) then begin can:=false; exit; end;
     if (use[x+j,y-j])and(x+j<=n)and(y-j>=1) then begin can:=false; exit; end;
     if (use[x-j,y+j])and(x+j>=1)and(y+j<=m) then begin can:=false; exit; end;
     if (use[x-j,y-j])and(x+j>=1)and(y-j>=1) then begin can:=false; exit; end;
     can:=true;
end;
procedure try(x,y,now:longint);
var
   i,j,k,nx,ny:longint;
   tuse:usetype;
begin
     if now>km[x,y] then km[x,y]:=now;
     if now+m div 3<km[x,y] then exit;
     if now>f[n] then f[n]:=now;
     if (x=n)and(y>m) then exit;
     if (now+m-y+1)+m div 5<f[x] then exit;
     if f[n-x]+now+m-y+1<f[n] then exit;
     if y=m then
        begin
             if x<>n then begin nx:=x+1; ny:=1; end else begin nx:=x; ny:=y+1; end;
             for i:=x to n do if now>f[i] then f[i]:=now else break;
        end else
        begin
         nx:=x; ny:=y+1;
        end;
     if use[x,y]=false then
     begin
          for j:=1 to 2 do
          if can(x,y,j) then
          begin
               tuse:=use;
               use[x,y]:=true; use[x+j,y+j]:=true; use[x+j,y-j]:=true;
               use[x-j,y+j]:=true; use[x-j,y-j]:=true;
               try(nx,ny,now+1);
               use:=tuse;
          end;
     end;
     try(nx,ny,now);
end;
begin
     init;
     fillchar(f,sizeof(f),0);
     fillchar(km,sizeof(km),0);
     now:=0;
     try(1,1,now);
     assign(output,'output2.txt');
     rewrite(output);
     writeln(f[n]);
     close(output);
end.

作 者:Fruit
共有3316位读者阅读过此文

  • 上篇文章《硬币找零》参考程序
  • 下篇文章分区初赛模拟卷选择题

  • 发送邮件
    保存页面 打印文章 HTML版本 发表评论

    □- 近期热门文章 □- 相关文章
    1. NOIP2006竞赛大纲 [8307]
    2. 七类高中生具有保送资格 [5911]
    3. NOI2006获奖选手名单 [4956]
    4. 关于举办NOIP2006模拟赛的通告 [4107]
    5. Turbo Pascal各语句运行速... [3595]
    6. Turbo王者归来新Delphi免费... [3182]
    7. IOI2006我国4名选手全部获得金... [2946]
    8. 关于APIO2007与IOI2007... [2764]
    9. noip倒计时 by 枯叶蝴蝶 [2684]
    10. 朱泽园:思想上的金牌更重要 [2169]
    6月28日PHOI友谊赛[更新]
    FruitOI-3 Html试题
    FruitOI3试题下载(doc)
    FruitOI-3友谊赛通知
    《神奇国度》参考程序
    《硬币找零》参考程序
    FOI&BBOI-2结果公布
    FOI&BBOI-2提交页面
    BBOI-2全部试题Word文档
    BBOI-2第四题《硬币找零》
     

    关于本站 | 合作伙伴 | 联系方式
    大榕树 版权所有 ©1999-2006 www.myDrs.org 闽ICP备05000721号