Bipartite pose = _ =
Binary Search:
1: The first number greater than or equal to xx
int bin_s(int xx){ int l=1,r=10; int ans=-1; while(l<=r){ int m=(l+r)>>1; if(a[m]>=xx) ans=m,r=m-1; //!!! else l=m+1; } return ans;}e.g: int a[]={0,1,2,5,5,5,5,7,8,9,10};in: 5out: 3
2: The first number greater than xx
Int bin_s (int xx) {int l = 1, r = 10; int ans =-1; while (l <= r) {int m = (l + r)> 1; if (a [m]> xx) ans = m, r = m-1 ;//!!! Else l = m + 1;} return ans;} e. g: int a [] = {, 5, 5, 10 };in: 5out: 7
3: The first number smaller than or equal to xx (close to xx)Int bin_s (int xx) {int l = 1, r = 10; int ans =-1; while (l <= r) {int m = (l + r)> 1; if (a [m]> xx) r = m-1; else ans = m, l = m + 1;} return ans;} e. g: int a [] = {, 10 };in: 5out: 6
4: the first number smaller than xx (close to xx)int bin_s(int xx){ int l=1,r=10; int ans=-1; while(l<=r){ int m=(l+r)>>1; if(a[m]>=xx) r=m-1; else ans=m,l=m+1; } return ans;}e.g: int a[]={0,1,2,5,5,5,5,7,8,9,10};in: 5out: 2