75 wa

#include <bits/stdc++.h>
using namespace std;

double a, b, c, d;

double fx(double x) {
    return a*x*x*x+b*x*x+c*x+d;
}

double finder(double l, double r) {
     for(int i=-100; i<=100; ++i){
        double mid=(l+r)/2;
        if (fx(mid)*fx(r) < 0) {
            l = mid;
        } 
        else {
            r = mid;
        }
    }
    return (l+r)/2;
}
vector<double> roots;
int main() {
   cin>>a>>b>>c>>d;
   
    for (int i = -100; i < 100; ++i) {
    double l = i;
    double r = i + 1.0;
    double fl = fx(l);
    double fr = fx(r);

    if (abs(fl) < 1e-6) { // 左端点是根
        roots.push_back(l); 
    } else if (fl * fr < 0) { // 区间内有根
        roots.push_back(finder(l,  r));
    }
    
   }

   

   sort(roots.begin(),roots.end()); 

   printf("%.2f %.2f %.2f", roots[0], roots[1], roots[2]);
   
}

0 comments

No comments so far...

Information

ID
723
Time
1000ms
Memory
256MiB
Difficulty
5
Tags
# Submissions
54
Accepted
20
Uploaded By