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

突然间发现255是像素值而不是宽的上限,指针的结果-RuntimeError郁闷~~~

Posted by lnw545454 at 2011-06-16 20:43:26 on Problem 1009
program p1009(input,output);
type
  pointer=^node;
  node=record
    a,b:longint;
    next:pointer;
  end;
var
  tot,pos:longint;
  w,a,b,i:longint;
  head,p,q:pointer;
  pre:array[0..255] of longint;
  h:longint;
procedure insert(a,b:longint);
begin
  if a=q^.a then inc(q^.b,b)
  else
  begin
    new(q^.next);
    q:=q^.next;
    q^.a:=a;
    q^.b:=b;
    q^.next:=nil;
  end;
end;
procedure doit(a,b:longint);
var
  t:pointer;
  count,ans,loc:longint;
begin
  ans:=0;
  inc(pos);
  h:=(h+1) mod 256;
  pre[h]:=a;
  if pos>w then
  begin
    count:=abs(pre[(h-w+256) mod 256]-a);
    if count>ans then ans:=count;
    if pos mod w<>1 then
    begin
      count:=abs(pre[(h-w+255) mod 256]-a);
      if count>ans then ans:=count;
    end;
    if pos mod w<>0 then
    begin
      count:=abs(pre[(h-w+257) mod 256]-a);
      if count>ans then ans:=count;
    end;
  end;
  if pos mod w<>1 then
  begin
    count:=abs(pre[(h+255) mod 256]-a);
    if count>ans then ans:=count;
  end;
  if pos mod w<>0 then
  if i=b then
  begin
    count:=abs(p^.next^.a-a);
    if count>ans then ans:=count;
  end;
  if pos<=tot-w then
  begin
    loc:=b-i;
    t:=p;
    while loc<w-1 do
    begin
      t:=t^.next;
      loc:=loc+t^.b;
    end;
    if pos mod w<>1 then
    begin
      count:=abs(t^.a-a);
      if count>ans then ans:=count;
    end;
    while loc<w do
    begin
      t:=t^.next;
      loc:=loc+t^.b;
    end;
    count:=abs(t^.a-a);
    if count>ans then ans:=count;
    if pos mod w<>0 then
    begin
      while loc<w+1 do
      begin
        t:=t^.next;
        loc:=loc+t^.b;
      end;
      count:=abs(t^.a-a);
      if count>ans then ans:=count;
    end;
  end;
  insert(ans,1);
end;
begin
  new(head);
  head^.a:=-1;
  head^.b:=-1;
  readln(w);
  writeln(w);
  while w<>0 do
  begin
    fillchar(pre,sizeof(pre),0);
    h:=255;
    tot:=0;
    pos:=0;
    q:=head;
    readln(a,b);
    while a<>0 do
    begin
      insert(a,b);
      inc(tot,b);
      readln(a,b);
    end;
    q:=head;
    p:=q^.next;
    while p<>nil do with p^ do
    begin
      if b<=2*w+2 then
        for i:=1 to b do doit(a,b)
      else
      begin
        for i:=1 to w+1 do doit(a,b);
        for i:=0 to 255 do pre[i]:=a;
        h:=255;
        insert(0,b-2*w-2);
        pos:=pos+b-2*w-2;
        for i:=b-w to b do doit(a,b);
      end;
      q^.next:=next;
      dispose(p);
      p:=q^.next;
    end;
    p:=head^.next;
    while p<>nil do
    begin
      writeln(p^.a,' ',p^.b);
      q:=p^.next;
      dispose(p);
      p:=q;
    end;
    writeln(0,' ',0);
    readln(w);
    writeln(w);
  end;
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