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

Re:TLe了 递推写的 哪里还可以优化吗?

Posted by L18 at 2009-06-15 02:28:50 on Problem 1404
In Reply To:TLe了 递推写的 哪里还可以优化吗? Posted by:___A___ at 2009-06-10 15:34:21
int Dis(const int pos_1,const int pos_2)
{
    int result=0,ptr=1;
    for (int i=pos_1;i<=pos_2;i++)
    {
        result+=value[i]*ptr;
        ptr++;
    }
    return result;
}

这个其实是多余的,如果用数组[][]预处理保存数值,可以做到O(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