二分模板
https://www.acwing.com/problem/content/791/
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 15;
int n, m, x;
int a[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
while(m--) {
cin >> x;
int l = 0, r = n - 1;
while(l < r) {
int mid = l + r >> 1;
if(a[mid] >= x) r = mid;
else l = mid + 1;
}
if(a[l] != x) cout << "-1 -1" << endl;
else {
cout << l << " ";
l = 0, r = n - 1;
while(l < r) {
int mid = l + r + 1 >> 1;
if(a[mid] <= x) l = mid;
else r = mid - 1;
}
cout << r << endl;
}
}
return 0;
}
https://www.acwing.com/problem/content/792/
#include<bits/stdc++.h>
using namespace std;
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
double n;
cin >> n;
double l = -100, r = 100;
while(abs(l - r) > 1e-8) {
double mid = (l + r) / 2;
if(mid * mid * mid > n) r = mid;
else l = mid;
}
printf("%.6lf", l);
return 0;
}