记录编号 571016 评测结果 AAAAA
题目名称 [NOIP 2001]一元三次方程求解 最终得分 100
用户昵称 Gravatarlihaoze 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2022-05-02 19:07:45 内存使用 0.00 MiB
显示代码纯文本
#include <bits/stdc++.h>
#define OPEN(_x) freopen(#_x".in", "r", stdin); freopen(#_x".out", "w", stdout)
#define rep(_x, _y, _z) for (int _x = (_y); _x <= (_z); ++ _x)
#define rep1(_x, _y, _z) for (int _x = (_y); _x < (_z); ++ _x)
#define fi first
#define se second

using i64 = long long;
using PII = std::pair<int, int>;

double a, b, c, d;
std::set<int> res;
std::set<double> output;

// x <- x - (ax^3 + bx^2 + cx + d) / (3ax^2 + 2bx + c)

void calc(double &x, std::function<double(double)> f, std::function<double(double)> df_dx) { 
    rep (i, 1, 50) x = x - f(x) / df_dx(x);
}

int main() {
    OPEN(3cfc);
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> a >> b >> c >> d;
    auto f = [&](double x) { return a * x * x * x + b * x * x + c * x + d; };
    auto df_dx = [&](double x) { return 3 * a * x * x + 2 * b * x + c; };
    rep (i, -100, 100) {
        double x = i;
        calc(x, f, df_dx);
        if (!res.count(int(x + 0.49))) output.insert(x);
        res.insert(int(x + 0.49));
    }
    for (auto i : output) printf("%.2f ", i);
    return 0;
}