思路一

intfind(inta[],intn){if(n==0)return-1;if(n==1)return0;if(n==2)returna[0]<=a[1]?0:1;intleft=0,right=n-1,mid;while(right-left>1){mid=left+(right-left)/2;if(a[left]<a[mid])left=mid;elseright=mid;}if(a[left]>a[right])returnright;elsereturn0;}intbinarySearch(inta[],intleft,intright,inttarget){intmid;while(left<=right){mid=left+((right-left)>>1);if(a[mid]==target)returnmid;elseif(a[mid]<target)left=mid+1;elseright=mid-1;}return-1;}intsearch(intA[],intn,inttarget){//three steps: cut the array into two sorted arrays;// search the target in two sorted arrays;// return the index;intindex=find(A,n);if(index==0)returnbinarySearch(A,0,n-1,target);else{if(target>=A[0])returnbinarySearch(A,0,index-1,target);elsereturnbinarySearch(A,index,n-1,target);}}