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

单调队列

Posted by 117474335 at 2010-09-14 15:53:11 on Problem 3214
大家注意了:
用单调队列时, 要设一个 ans = 0 ;表示答案 ;也表示最长长度; 更表示所维护的最长队列的长度; 
由最后一条得知: 
当插入元素时不要将队列长度变为插入位置的坐标, 因为实际的队列长度要比这个长!
因此只能不断将队列长度增加, 而不能将队列长度 变小 ; 
附一段简单代码(求最长不下降子序列):
ans = 0 ;
for (i = 1 ; i <= ; i ++ ){
   head = 1 ; tail = ans + 1 ;
   while (head < tail){
       mid = (head + tail) >> 1 ;
       if (q[mid] > w[i]) tail = mid ;
       else head = mid + 1 ; }
   if (tail == ans + 1) ans ++ ;
   q[tail] = w[i] ; } 
总结:
当不能保证该点不能被用时, 就只能将范围缩小至此;
而可以保证该点不能被用时, 就可以将此点排除在外; 



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