回 帖 发 新 帖 刷新版面

主题:usaco 1.4 checker 超时

输入13 超时
源程序:

program checker(input,output);
var
  a:array[0..15]of boolean;
  b:array[-15..15]of boolean;
  c:array[0..30]of boolean;
  num:array[0..15]of integer;
  n:integer;
  sum:longint;
  time:longint;
procedure try(ceng:integer);
  var i:integer;
  begin
    if ceng>n then
      begin
        inc(sum);
        if sum<=3 then
          begin
            for i:=1 to n-1 do write(num[i],' ');
            writeln(num[n]);
          end;
      end
    else for i:=1 to n do
      if (not a[i])and(not b[ceng-i])and(not c[ceng+i]) then
        begin
          a[i]:=true;
          b[ceng-i]:=true;
          c[ceng+i]:=true;
          num[ceng]:=i;
          try(ceng+1);
          a[i]:=false;
          b[ceng-i]:=false;
          c[ceng+i]:=false;
          num[ceng]:=0;
        end;
  end;
begin
  assign(input,'checker.in');
  assign(output,'checker.out');
  reset(input);
  rewrite(output);
{ time:=meml[$40:$6c];}
  readln(n);
  try(1);
  writeln(sum);
{ writeln((meml[$40:$6c]-time)/18.4:0:2);}
  close(input);
  close(output);
end.
帮我改一下

回复列表 (共3个回复)

沙发

program nqueen;
var
a:array[0..14] of boolean;
b:array[-14..14] of boolean;
c:array[-27..27] of boolean;
outx:array[0..14] of byte;
foundx,n:longint;


procedure findx(dep:byte);
var j,k:byte;
begin
for j:=1 to n do
if a[j] and b[dep-j] and c[dep+j] then begin
  a[j]:=false;
  b[dep-j]:=false;
  c[dep+j]:=false;
  outx[dep]:=j;
if dep=n then
begin
  inc(foundx);

  if foundx<=3 then begin
  for k:=1 to n-1 do write(outx[k],' ');
  writeln(outx[n]);
  end;
end
else findx(dep+1);
a[j]:=true;
b[dep-j]:=true;
c[dep+j]:=true;
end;
end;



begin
assign(input,'checker.in');
assign(output,'checker.out');
reset(input);
rewrite(output);
readln(n);

fillchar(a,sizeof(a),true);
fillchar(b,sizeof(b),true);
fillchar(c,sizeof(c),true);
foundx:=0;
findx(1);
writeln(foundx);
close(input);
close(output);
end.

板凳

也超时……

我的机器评测:466MHz 5.16s
USACO 是 P3 800 ,1s怎么过的?

3 楼

试了很多遍
Test 1 OK [0 secs]
Test 2 OK [0 secs]
Test 3 OK [0 secs]
Test 4 OK [0.01 secs]
Test 5 OK [0.02 secs]
Test 6 OK [0.07 secs]
Test 7 OK [0.36 secs]
Execution error: Your program (`checker') used more than the allotted
runtime of 1 seconds (it ended or was stopped at 2 seconds) when
presented with test case 8, shown below.

----- Test Case 8 ------
13
----------------------------

我来回复

您尚未登录,请登录后再回复。点此登录或注册