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 |
我自己写了个快排,AC了它,哈哈,再也不想用algorithmIn Reply To:破题,还以为是最多能装多少,6+11+11=28<40,结果又看一遍题就AC了。 Posted by:julyflame at 2009-03-04 13:06:39 void Qsort(int low, int high) { if (low >= high) { return ; } int l, mid, r, pivot; //mid = low +(high-low)>>1; // + -的优先级比>>还大,又一次在这里翻船了!!!! mid = low + (high-low>>1); Swap(arr[mid], arr[high]); l = low, r = high-1; while (l<=r) { while (l<=r && arr[l] <= arr[high]) { l++; } while (l<=r && arr[r] >= arr[high]) { r--; } if (l<=r) { Swap(arr[l], arr[r]); l++; r--; } if (l>r) { pivot = l; break; } } Swap(arr[pivot], arr[high]); Qsort(low, pivot-1); Qsort(pivot+1, high); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator