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 eche at 2013-03-07 19:52:47 on Problem 2533
int n;//stack size
int Stack[1005];

int bsearch(int num)
{
    int i,j,k;
    for(i=0,j=n-1;i<=j;)
    {
        k=(i+j)/2;
        if(Stack[k]>num)
            j=k-1;        
        else 
            i=k+1;
    }
    return i;
}

一开始写成i<j WA了,考虑栈内有1,3,5找bsearch(2)就能看出错误了。

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