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

和3061一样的做法,单向队列

Posted by sw81500345 at 2011-08-24 00:08:59 on Problem 2140
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:
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