【洛谷】P1024 一元三次方程求解 (题解)

P1024 一元三次方程求解 


题解:

#include <bits/stdc++.h>
using namespace std;
int main()
{
   double a,b,c,d;
   cin>>a>>b>>c>>d;
   for(double i=-100;i<=100;i+=0.001)
   {
      double j=i+0.001;
      double y1=a*i*i*i+b*i*i+c*i+d;
      double y2=a*j*j*j+b*j*j+c*j+d;
      if(y1>=0&&y2<=0||y1<=0&&y2>=0)
      {
         double x=(i+j)/2;
         printf("%.2lf ",x);
      }
   }
   return 0;
}

 

posted @ 2020-02-12 16:27  BorisDimitri  阅读(27)  评论(0编辑  收藏  举报