| ||||||||||
| 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 | |||||||||
和3061一样的做法,单向队列var
a:array[0..10000000] of longint;
head,tail,n,i,sum,ans:longint;
begin
readln(n);
for i:=1 to n do a[i]:=i;
head:=1; tail:=1;
ans:=0; sum:=1;
while tail<=n do
begin
if sum=n then begin inc(ans); end;
if sum>=n then begin inc(head); sum:=sum-a[head-1]; end;
if sum<n then begin inc(tail); sum:=sum+a[tail]; end;
end;
writeln(ans);
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator