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

哪位大牛能帮我看看这个程序有什么错?我实在想不出什么数据了可以wa了……

Posted by wangchen1ren at 2004-06-07 12:57:16 on Problem 1659
program p1659;
var s:array[0..20,0..20]of byte;
    c,p:array[1..20]of longint;
    n,t,i:longint;

procedure sort(l,r:longint);
  var i,j,x,y:longint;
begin
  i:=l;j:=r;x:=c[(l+r) DIV 2];
  repeat
    while c[i]<x do i:=i+1;
    while x<c[j] do j:=j-1;
    if i<=j then begin
      y:=c[i];c[i]:=c[j];c[j]:=y;
      y:=p[i];p[i]:=p[j];p[j]:=y;
      i:=i+1;j:=j-1;
    end;
  until i>j;
  if l<j then sort(l,j);
  if i<r then sort(i,r);
end;

procedure init;
  var i:longint;
begin
  readln(n);
  for i:=1 to n do begin
    read(c[i]);
    p[i]:=i;
  end;
  sort(1,n);
  fillchar(s,sizeof(s),0);
end;

procedure print;
  var i,j:longint;
begin
  for i:=1 to n do begin
    for j:=1 to n do
      write(s[i,j],' ');
    writeln;
  end;
end;

procedure work;
  var i,j:longint;
      bool:boolean;
begin
  i:=n;bool:=true;
  while (bool)and(i>0) do begin
    j:=i-1;
    while (bool)and(c[i]>0) do begin
      while (j>0)and(c[j]<=0) do dec(j);
      if j<=0 then bool:=false
      else begin
        dec(c[i]);dec(c[j]);
        s[p[i],p[j]]:=1;s[p[j],p[i]]:=1;
        dec(j);
      end;
    end;
    dec(i);
  end;
  if bool then begin
    writeln('YES');
    print;
  end
  else writeln('NO');
end;


begin
//  assign(input,'input.txt');reset(input);
//  assign(output,'output.txt');rewrite(output);
  readln(t);
  for i:=1 to t do begin
    init;
    work;
    if i<>t then 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