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

第一次tle,第二次ac

Posted by 200730690105 at 2009-03-19 04:32:43 on Problem 1781
第一次我的思路很清晰但超时,把数列输出来发现了规律,于是得出了第二种算法,却无法解释,复杂度由O(n)变为了O(logn),结果ac
现把两次的思路写出来
(TLE)
a[1]=1;
for(i=2;i<=99000000;i++)
{
     a[i]=(a[i-1]+1)%i+1;
}

(AC)
当n=2^i(i=0,1,2...26)时 (2^26<99000000<2^27)也就是为2的幂时f(n)=1
当n为奇数时,f(n)=f(n/2)*2+1
当n不为2的幂且n为偶数时f(n)=f(n/2)*2-1

希望有大牛能够解释一下第二种算法的原理,最好再总结出一个公式并给出证明

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