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 |
哪位大牛帮忙看看 二分 why WA?#include<stdio.h> int a[1010],b[1010]; int binary(int *s,int m,int n) { int left,right,mid; left=1; right=m; while(left<right-1) { mid=(left+right)/2; if(s[mid]<=n) left=mid; else right = mid; } if(s[left]>n) return left; return right; } int main() { int i,j,k; int t; while(scanf("%d",&t)!=EOF) { for(i=1;i<=t;i++) scanf("%d",&a[i]); b[1]=a[1]; k=1; for(i=2;i<=t;i++) { if(a[i]>=b[k]) { k++; b[k]=a[i]; } else { j=binary(b,k,a[i]); b[j]=a[i]; } } printf("%d\n",k); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator