Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位大哥帮忙看看啊~~~救命啊~1014

Posted by hu_xb111 at 2005-08-27 17:24:27 on Problem 1014
var
  num,target:array[1..6] of longint;
  i,j,k,tot:longint;
  ans:boolean;
procedure check;
  var temp,p:longint;
  begin
    temp:=0;
    for p:=1 to 6 do temp:=temp+target[p]*p;
    if temp=tot div 2 then
      ans:=true;
  end;
procedure search(level:longint);
  var min,max,t:longint;
  begin
    if level=7 then begin
      check;
      exit;
    end;
    if (level=1) or (level=5) then begin
      if num[level]<=5 then begin
        min:=0;
        max:=num[level];
      end
      else begin
             max:=(5+num[level]) div 2;
             if odd(num[level]) then min:=(num[level]-5) div 2
                                else min:=(num[level]-4) div 2;
           end;
    end
    else begin
      if num[level]<=6 then begin
        min:=0;
        max:=num[level];
      end
      else begin
             max:=(6+num[level]) div 2;
             if odd(num[level]) then min:=(num[level]-6) div 2
                                else min:=(num[level]-5) div 2;
           end;
    end;
    if num[level]=0 then search(level+1)
                    else
                      for t:=min to max do begin
                        target[level]:=t;
                        search(level+1);
                      end;
  end;
begin
{  assign(input,'1014.in'); reset(input);
  assign(output,'1014.out'); rewrite(output);}
  k:=0;
  while true do begin
    tot:=0;
    for i:=1 to 6 do begin
      read(num[i]);
      tot:=tot+i*num[i];
    end;
    if tot=0 then break;
    inc(k);
    if odd(tot) then begin
      writeln('Collection #',k,':');
      writeln('Can ','''','t be divided.');
      writeln;
    end;
    ans:=false;
    fillchar(target,sizeof(target),0);
    search(1);
    writeln('Collection #',k,':');
    if ans then writeln('Can be divided.')
           else writeln('Can ','''','t be divided.');
    writeln;
  end;
{  close(input); close(output);}
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator