usaco1.3 crypt1 2008.11.5

usaco1.3 crypt1 2008.11.5

{Tips

1.用到了哈希判重

2.这是一道简单的题,只要耐心就行了。}

{

ID:

PROG: crypt1

LANG: PASCAL

}

 program kakashi;
   const
     oo:array[1..9]of char=('1','2','3','4','5','6','7','8','9');
    var
      num:array[1..9,1..9,1..9,1..9]of -1..1;
      x,i,j,k,m,n,p,tot:longint;
      a:array[1..9]of 1..9;
      b:set of '0'..'9';
      f1,f2:text;
    function deal(uu,la,lb:longint):boolean;
    var
      ux:string;
      lx,s:longint;
      begin
        if (uu>la)and(uu<lb) then
          begin
            str(uu,ux);
            lx:=length(ux);
            deal:=true;
            for s:=1 to lx do
             if not(ux[s]in b) then deal:=false;
          end
          else deal:=false;
      end;
    procedure find(y:longint);
      begin
          if deal(x*a[y],99,1000) then num[i,j,k,y]:=1 else num[i,j,k,y]:=-1;
      end;

  begin
      assign(f1,'crypt1.in');
      reset(f1);
      assign(f2,'crypt1.out');
      rewrite(f2);
      readln(f1,p);
      fillchar(num,sizeof(num),0);
      tot:=0;
      for i:=1 to p do
        read(f1,a[i]);
      for i:=1 to p do
        b:=b+[oo[a[i]]];
      for i:=1 to p do
        for j:=1 to p do
          for k:=1 to p do
            begin
              x:=100*a[i]+10*a[j]+a[k];
              for m:=1 to p do
                if (num[i,j,k,m]<>-1) then
                begin
                   if (num[i,j,k,m]=0) then
                       find(m);
                       if num[i,j,k,m]=1 then
                          for n:=1 to p do
                             if (num[i,j,k,n]<>-1) then
                          {=3=}begin
                                 if num[i,j,k,n]=0 then
                                     find(n);
                                     if num[i,j,k,n]=1 then
                                       if (deal(x*(10*a[m]+a[n]),999,10000)) then
                                         inc(tot);
                          {=3=}end;
        {=1=}   end;

          end;
          writeln(f2,tot);
          close(f1);
          close(f2);
          end.


data

TASK: crypt1

LANG: PASCAL

 

Compiling...

Compile: OK

 

Executing...

     Test 1: TEST OK [0 secs]

     Test 2: TEST OK [0.004 secs]

     Test 3: TEST OK [0.004 secs]

     Test 4: TEST OK [0 secs]

     Test 5: TEST OK [0.004 secs]

     Test 6: TEST OK [0.004 secs]

     Test 7: TEST OK [0.004 secs]

 

All tests OK.

YOUR PROGRAM ('crypt1') WORKED FIRST TIME!  That's fantastic

-- and a rare thing.  Please accept these special automated

congratulations.

 

Here are the test data inputs:

 

 

------- test 1 -------

5

2 3 4 6 8

------- test 2 -------

4

2 3 5 7

------- test 3 -------

1

1

------- test 4 -------

7

4 1 2 5 6 7 3

------- test 5 -------

8

9 1 7 3 5 4 6 8

------- test 6 -------

6

1 2 3 5 7 9

------- test 7 -------

9

1 2 3 4 5 6 7 8 9

----------------------

 

Keep up the good work!

 

 

Thanks for your submission!

 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值