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 |
help!!!!!!!!!!!!!!!!Give me you hand......thanks,Why WA??????#include <iostream> using namespace std; int a[5005]; int b[5005]; int bi(int i,int k)//二分查找 { int h,j; if(a[i]<b[1])return 1; for(h=1,j=k;h!=j-1;) { if(b[k=(h+j)/2]<=a[i])h=k; else j=k; } return j; } int main() { int n; int i,k; while(scanf("%d",&n)!=EOF){ memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(i=0;i<n;i++) scanf("%d",&a[i]); b[1]=a[0]; for(i=1,k=1;i<n;i++) { if(a[i]>=b[k]) b[++k]=a[i]; else b[bi(i,k)]=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