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

代码3600b...及其混乱,张贴示众

Posted by The_Dawn at 2011-03-19 17:27:55 on Problem 1208
听着庐州月...
自己都不知道怎么写成这样的,还一A了.


type
  rec=record
    c,l:integer;
  end;
var
  col:array[0..25,0..25]of integer;
  p:array[0..25]of rec;
  s:string;
  a,b,i,j,k,n:longint;
  op1,op2:string;

procedure renew;
  begin
    fillchar(col,sizeof(col),0);
  end;

procedure monto(a,b:longint);
  var
    i,tmp:integer;
  begin
    if (a=b)or(p[a].c=p[b].c) then exit;
    for i:=p[a].l+1 to col[p[a].c,0] do
      begin
        tmp:=col[p[a].c,i];
        dec(col[p[a].c,0]);
        inc(col[tmp,0]);
        col[tmp,col[tmp,0]]:=tmp;
        p[tmp].c:=tmp;p[tmp].l:=col[tmp,0];
      end;
    for i:=p[b].l+1 to col[p[b].c,0] do
      begin
        tmp:=col[p[b].c,i];
        dec(col[p[b].c,0]);
        inc(col[tmp,0]);
        col[tmp,col[tmp,0]]:=tmp;
        p[tmp].c:=tmp;p[tmp].l:=col[tmp,0];
      end;
    inc(col[p[b].c,0]);
    col[p[b].c,col[p[b].c,0]]:=a;
    dec(col[p[a].c,0]);
    p[a].c:=p[b].c;
    p[a].l:=p[b].l+1;
  end;

procedure mover(a,b:longint);
  var
    i,tmp:integer;
  begin
    if (a=b)or(p[a].c=p[b].c) then exit;
    for i:=p[a].l+1 to col[p[a].c,0] do
      begin
        tmp:=col[p[a].c,i];
        dec(col[p[a].c,0]);
        inc(col[tmp,0]);
        col[tmp,col[tmp,0]]:=tmp;
        p[tmp].c:=tmp;p[tmp].l:=col[tmp,0];
      end;
    inc(col[p[b].c,0]);
    col[p[b].c,col[p[b].c,0]]:=a;
    dec(col[p[a].c,0]);
    p[a].c:=p[b].c;
    p[a].l:=col[p[b].c,0];
  end;

procedure ponto(a,b:longint);
  var
    i,tmp,de,ac,al:integer;
  begin
    if (a=b)or(p[a].c=p[b].c) then exit;
    de:=0;
    for i:=p[b].l+1 to col[p[b].c,0] do
      begin
        tmp:=col[p[b].c,i];
        dec(col[p[b].c,0]);
        inc(col[tmp,0]);
        col[tmp,col[tmp,0]]:=tmp;
        p[tmp].c:=tmp;p[tmp].l:=col[tmp,0];
      end;
    ac:=p[a].c;al:=p[a].l;
    for i:=al to col[ac,0] do
      begin
        tmp:=col[ac,i];
        inc(de);
        inc(col[p[b].c,0]);
        col[p[b].c,col[p[b].c,0]]:=tmp;
        p[tmp].c:=p[b].c;p[tmp].l:=col[p[b].c,0];
      end;
    dec(col[ac,0],de);
  end;

procedure pover(a,b:longint);
  var
    i,tmp,de,ac,al:integer;
  begin
    if (a=b)or(p[a].c=p[b].c) then exit;
    de:=0;
    ac:=p[a].c;
    al:=p[a].l;
    for i:=al to col[ac,0] do
      begin
        tmp:=col[ac,i];
        inc(de);
        inc(col[p[b].c,0]);
        col[p[b].c,col[p[b].c,0]]:=tmp;
        p[tmp].c:=p[b].c;p[tmp].l:=col[p[b].c,0];
      end;
    dec(col[ac,0],de);
  end;

procedure init_dawn;
  var
    tmp:string;
    tp,i:integer;
  begin
    readln(n);
    for i:=0 to n-1 do
      begin
        inc(col[i,0]);col[i,1]:=i;
        p[i].c:=i;p[i].l:=1;
      end;
    repeat
      readln(s);
      if s='quit' then break;
      op1:=copy(s,1,4);
      delete(s,1,5);
      tp:=pos(' ',s);
      val(copy(s,1,tp-1),a);
      delete(s,1,tp);
      op2:=copy(s,1,4);
      delete(s,1,5);
      val(s,b);
      if op1='move' then
        if op2='onto' then monto(a,b)
        else if op2='over' then mover(a,b);
      if op1='pile' then
        if op2='onto' then ponto(a,b)
        else if op2='over' then pover(a,b);
    until s='quit';
  end;

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

begin
  //assign(input,'1.txt');
  //assign(output,'2.txt');
  //reset(input);rewrite(output);

  repeat
    renew;
    init_dawn;
    print;
  until seekeof;

  //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