从卿学姐那里偷来的模板 (整数二分 待更新更加高级的
int left = 0,ri =maxn;
int ans = -1; while (left <= ri) { int mid = (left + ri)/2; if( check(mid) ) ans=mid,left = mid+1; else ri= mid-1; } cout << ans <<endl;
这个是double 类型的二分板子
double left = 0,ri =maxn; double ans = 0; for(int i=0; i<100; i++) { double mid = (left + ri)/2.0; if(check (mid)) ans = mid, le = mid; else ri = mid; } cout<< ans <<endl;