some programs!!!
This commit is contained in:
1 parent
71f1022dea
commit
ca6daa582c
43 files changed
+1452
-381
No files matched your search
@@ -0,0 +1,29 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
constexpr float ALLOWED_DIFF = 1e-6;
|
||||
|
||||
std::tuple<int, double> sqrt_custom(double x) {
|
||||
double est_prev = -1, est_curr = x;
|
||||
int rounds = 0;
|
||||
while (abs(est_curr - est_prev) > ALLOWED_DIFF) {
|
||||
est_prev = est_curr;
|
||||
// est_curr = 0.5 * (est_prev + x / est_prev);
|
||||
est_curr = x / (2 * est_curr) + 0.5 * est_curr;
|
||||
rounds++;
|
||||
}
|
||||
return std::make_tuple(rounds, est_curr);
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
int x;
|
||||
while (std::cin >> x) {
|
||||
auto [rounds, ans] = sqrt_custom(x);
|
||||
std::cout << rounds << " " << std::fixed << std::setprecision(2) << ans << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user