Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
二分搜索引起的错误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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator