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

1AC PASCAL

Posted by qiuwenhua at 2012-08-21 16:44:27 on Problem 2081
var a:array[0..500020] of longint;
    f:array[0..5000000] of boolean;
    i,n:longint;
begin
  fillchar(f,sizeof(f),true);
  a[0]:=0;
  f[0]:=false;
  for i:=1 to 500010 do
  if (a[i-1]-i)>=0 then
  begin
  if f[a[i-1]-i] then
  begin
    a[i]:=a[i-1]-i;
    f[a[i]]:=false;
  end
  else if not f[a[i-1]-i] then
  begin
    a[i]:=a[i-1]+i;
    f[a[i]]:=false;
  end;
  end
  else begin
         a[i]:=a[i-1]+i;
         f[a[i]]:=false;
   end;
  readln(n);
  while n<>-1 do
  begin
    writeln(a[n]);
    readln(n);
  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