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 |
Re:我的快排过不了啊,总是TLE,求优化。(附代码)(虽然用STL过了)In Reply To:我的快排过不了啊,总是TLE,求优化。(附代码)(虽然用STL过了) Posted by:00946188 at 2010-10-08 18:33:30 > void qs(int s[],int l,int r) > { > int p,i,j; > int t,temp; > if(l>=r) > return; > if(r-l<=16) > { > for(i=l;i<r;i++) > for(j=i+1;j<=r;j++) > if(s[i]>s[j]) > { > t=s[i]; > s[i]=s[j]; > s[j]=t; > } > return; > } > p=rand()%(r-l)+l; > temp=s[p]; > s[p]=s[r]; > for(j=r,i=-1;i<j;) > { > for(;i<j;) > if(s[++i]>temp) > { > s[j]=s[i]; > break; > } > for(;i<j;) > if(s[--j]<temp) > { > s[i]=s[j]; > break; > } > } > s[i]=temp; > qs(s,l,i-1); > qs(s,i+1,r); > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator