宋壬初吧 关注:25贴子:419
  • 0回复贴,共1

重庆省选第四题程序

收藏回复

  • 221.194.73.*
var i,j,k,l,m,n,sum,many,winlose,tie,oup:longint;
    score:array[1..8] of longint;
    can,tt:longint;
    mid:array[1..8] of longint;
    pd:boolean;
procedure sc(x,y:longint);
var g,t,l,r:longint;
begin
  if x=n then
    begin
      inc(oup);  
      exit;
    end;
  if winlose<can then
    begin
      inc(winlose);
      if mid[x]<=score[x]-3 then
        begin
          inc(mid[x],3);
          if y<n then sc(x,y+1) else
            if mid[x]=score[x] then sc(x+1,x+2);
          dec(mid[x],3);  
        end;
      if mid[y]<=score[y]-3 then
        begin
          inc(mid[y],3);
          if y<n then sc(x,y+1) else
            if mid[x]=score[x] then sc(x+1,x+2);
          dec(mid[y],3);  
        end;
      dec(winlose);  
    end;
  if tie<tt then
    begin
      inc(tie);
      if (mid[x]<score[x])and(mid[y]<score[y]) then
        begin
          inc(mid[x]);inc(mid[y]);
          if y<n then sc(x,y+1) else
            if mid[x]=score[x] then sc(x+1,x+2);
          dec(mid[x]);dec(mid[y]);  
        end;
      dec(tie);  
    end;
end;    
begin
  read(n);
  for i:=1 to n do
    begin
      read(score[i]);
      inc(sum,score[i]);
    end;
  for i:=1 to n-1 do
    for j:=i+1 to n do
      if score[i]<score[j] then
        begin
          l:=score[i];score[i]:=score[j];score[j]:=l;
        end;  
  many:=n*(n-1) div 2;
  for i:=0 to many do
    if 3*i+2*(many-i)=sum then
      begin
        can:=i;tt:=many-i;
        break;
      end;
  oup:=0;
  fillchar(mid,sizeof(mid),0);
  winlose:=0;tie:=0;
  sc(1,2);  
  writeln(oup);  
end.


1楼2009-10-30 09:52回复