0 0 虽然不知不觉做到了Section 1.4了,但是都没有把做题的想法和代码发到这里… 本来今天想从Section 1.2补起来然后发现之前做的题都忘了…(Name That Number那道题是今年3月20日做的,记得才怪呢。)

做Clocks这道题可谓一波三折。题目很好懂,我也很自然地想到了广搜的算法——第三点数据就超时!加了优化,第六点又超时。没辙了,参考网上题解:(1)转的先后没有关系;(2)转4次等于没转。于是只要穷举T T。

唯一让人欣慰的就是确定穷举算法之后一下子就写对了,从头写到尾都没再修改。提交全对的时候已经是Submission #8了。

tt数组是各种转法,t数组用于0、1、2、3穷举,

program clock3;
const tt:array[1..9,1..9] of word=((1,1,0,1,0,0,0,0,0),(1,1,1,0,1,0,0,0,0),(0,1,1,0,0,1,0,0,0),(1,0,0,1,1,0,1,0,0),(1,0,1,0,1,0,1,0,1),(0,0,1,0,1,1,0,0,1),(0,0,0,1,0,0,1,1,0),(0,0,0,0,1,0,1,1,1),(0,0,0,0,0,1,0,1,1));
var q_or,q_now:array[1..9] of word;
    t,ans:array[1..10] of word;
    i,j,k:integer;
    ansn,ansnt,ttt:integer;
    flag:boolean;
    ans_out:array[1..50] of word;
begin
  assign(input,'clocks.in');reset(input);
  assign(output,'clocks.out');rewrite(output);
  for i:=1 to 3 do
    begin
      for j:=1 to 3 do
        read(q_or[3*(i-1)+j]);
      readln;
    end;
  ansn:=32766;
  t[1]:=1;
  while t[10]<>1 do
    begin
      q_now:=q_or;
      for i:=1 to 9 do
        for j:=1 to t[i] do
          for k:=1 to 9 do
            begin
              if tt[k,i]=1 then q_now[k]:=(q_now[k]+2) mod 12+1;
            end;
      flag:=true;
      for i:=1 to 9 do
        if q_now[i]<>12 then flag:=false;
      if flag then
        begin
          ansnt:=0;
          for i:=1 to 9 do
            ansnt:=ansnt+t[i];
          if ansnt<=ansn then
            begin
              ansn:=ansnt;
              ans:=t;
            end;
        end;
      t[1]:=t[1]+1;
      i:=1;
      while t[i]=4 do
        begin
          t[i]:=0;
          t[i+1]:=t[i+1]+1;
          inc(i);
        end;
    end;
  //writeln(ansn);
  ttt:=0;
  for i:=1 to 9 do
    for j:=1 to ans[i] do
      begin
        inc(ttt);
        ans_out[ttt]:=i;
      end;
  for i:=1 to ttt-1 do
    write(ans_out[i],' ');
  writeln(ans_out[ttt]);
  close(input);close(output);
end.
Clocks

 

 posted on 2013-11-30 15:10  Sky-Grey  阅读(237)  评论(0编辑  收藏  举报