Section 1.4 The Clocks

时间:2023-03-09 06:36:25
Section 1.4 The Clocks

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[..,..] of word=((,,,,,,,,),(,,,,,,,,),(,,,,,,,,),(,,,,,,,,),(,,,,,,,,),(,,,,,,,,),(,,,,,,,,),(,,,,,,,,),(,,,,,,,,));
var q_or,q_now:array[..] of word;
t,ans:array[..] of word;
i,j,k:integer;
ansn,ansnt,ttt:integer;
flag:boolean;
ans_out:array[..] of word;
begin
assign(input,'clocks.in');reset(input);
assign(output,'clocks.out');rewrite(output);
for i:= to do
begin
for j:= to do
read(q_or[*(i-)+j]);
readln;
end;
ansn:=;
t[]:=;
while t[]<> do
begin
q_now:=q_or;
for i:= to do
for j:= to t[i] do
for k:= to do
begin
if tt[k,i]= then q_now[k]:=(q_now[k]+) mod +;
end;
flag:=true;
for i:= to do
if q_now[i]<> then flag:=false;
if flag then
begin
ansnt:=;
for i:= to do
ansnt:=ansnt+t[i];
if ansnt<=ansn then
begin
ansn:=ansnt;
ans:=t;
end;
end;
t[]:=t[]+;
i:=;
while t[i]= do
begin
t[i]:=;
t[i+]:=t[i+]+;
inc(i);
end;
end;
//writeln(ansn);
ttt:=;
for i:= to do
for j:= to ans[i] do
begin
inc(ttt);
ans_out[ttt]:=i;
end;
for i:= to ttt- do
write(ans_out[i],' ');
writeln(ans_out[ttt]);
close(input);close(output);
end.

Clocks