| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
1AC PASCALvar 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator