11 条题解

  • 1
    @ 2025-9-14 16:18:47

    我是 高手 初学者,能AC就行~

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    using namespace std;
    int main()
    {
    	double a,b,c,x1,x2;
    	cin >> a >> b >> c;
    	if(a == 0 || b*b - 4*a*c < 0)
    		cout << "No answer!";
    	else
    	{
    		x1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
    		x2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
    		if(x1 == x2)
    			printf("x1=x2=%.5f",x1);
    		else
    		{
    			if(x1 > x2)
    				swap(x1,x2);
    			printf("x1=%.5f;x2=%.5f",x1,x2);
    		}
    	}
    	
    	return 0;
    }
    
    • 1
      @ 2025-7-4 18:47:59
      #include <stdio.h>
      #include <math.h>
      #include <iostream>
      using namespace std;
      int main()
      {
      	double x1,x2;
      	double a,b,c;
          cin >> a >> b >> c;
          if ((b * b - 4 * a * c) < 0)
          {
              cout<<"No answer!";
          }
          else
          {
              if((b * b - 4 * a * c) == 0)
              {
              	x1 = -1 * (b / (2 * a));
                  printf("X1=X2=%.5lf\n",x1);
              }
              else
              {
              	x1 = (-b + sqrt(b*b - 4*a*c))/(2*a);
              	x2 = (-b - sqrt(b*b - 4*a*c))/(2*a);
                  if(x1 > x2)
                  {
                      swap(x1,x2);
                  }
                  printf("x1=%.5lf;x2=%.5lf\n",x1,x2);
              }
          }
      
      }
      
      • 1
        @ 2024-12-1 19:01:57
        #include<bits/stdc++.h>
        using namespace std;
        const int INF=0x3f3f3f3f;
        int const N=1e5+10;
        double a,b,c;
        int main(){
        	cin>>a>>b>>c;
        	double x1=(-b+sqrt(b*b-4*a*c))/(2*a),x2=(-b+-sqrt(b*b-4*a*c))/(2*a);
        	if(a==0){
        		cout<<"No answer!";
        		return 0;
        	}else if(b*b-4*a*c<0){
        		cout<<"No answer!";
        		return 0;
        	}
        	else if(x1==x2){
        		cout<<"x1=x2="<<fixed<<setprecision(5)<<x1;
        	}else if(x1<x2){
        		cout<<"x1="<<fixed<<setprecision(5)<<x1<<";x2="<<fixed<<setprecision(5)<<x2;
        	}else if(x1>x2){
        		cout<<"x1="<<fixed<<setprecision(5)<<x2<<";x2="<<fixed<<setprecision(5)<<x1;
        	}
        	return 0;
        }
        
        • 1
          @ 2023-3-26 20:25:11

          876AC代码,之前的题解都是错的

          //需注意:当b*b-4*a*c<0时,没有答案
          #include<iostream>
          #include<iomanip>
          #include<stdio.h>
          #include<math.h>
          using namespace std;
          int main(){
          	double a,b,c,x,y;
          	cin>>a>>b>>c;
          	if(a==0||b*b-4*a*c<0){
          		cout<<"No answer!";
          		return 0;
          	}
          	x=(-b+sqrt(b*b-4*a*c))/(2*a);
          	y=(-b-sqrt(b*b-4*a*c))/(2*a);
          	if(fabs(x-y)<1e-6){
          		printf("x1=x2=%.5lf",x);
          		return 0;
          	} 
          	if(x>y)swap(x,y);
          	printf("x1=%.5lf;x2=%.5lf",x,y);
          	return 0;
          }
          
          • 0
            @ 2022-8-16 11:30:35
            #include <stdio.h>
            #include <math.h>
            #include <iostream>
            using namespace std;
            int main()
            {
            	double a,b,c;
                cin >> a >> b >> c;
                if (a==0)
                {
                    cout<<"No answer!";
                }
                else
                {
                    double x1,x2;
                    x1 = (-b + sqrt(b*b - 4*a*c))/(2*a);
                    x2 = (-b - sqrt(b*b - 4*a*c))/(2*a);
                    if( fabs(x1-x2)< 1e-6)
                    {
                        printf("X1=X2=%.5lf\n",x1);
                    }
                    else
                    {
                        if(x1 > x2)
                        {
                            swap(x1,x2);
                        }
                        printf("x1=%.5lf;x2=%.5lf\n",x1,x2);
                    }
                }
            
            }
            
            • -1
              @ 2023-3-26 22:01:02
              #include <stdio.h>
              #include <math.h>
              #include <iostream>
              using namespace std;
              int main()
              {
              	double a,b,c;
                  cin >> a >> b >> c;
                  if (a==0)
                  {
                      cout<<"No answer!";
                  }
                  else
                  {
                      double x1,x2;
                      x1 = (-b + sqrt(b*b - 4*a*c))/(2*a);
                      x2 = (-b - sqrt(b*b - 4*a*c))/(2*a);
                      if( fabs(x1-x2)< 1e-6)
                      {
                          printf("X1=X2=%.5lf\n",x1);
                      }
                      else
                      {
                          if(x1 > x2)
                          {
                              swap(x1,x2);
                          }
                          printf("x1=%.5lf;x2=%.5lf\n",x1,x2);
                      }
                  }
              
              }
              
              • -1
                @ 2023-3-10 20:00:03

                真题解


                https://jingyan.baidu.com/article/ca00d56c2e0952e99eebcf86.html


                不会一元二次的人一定要看

                完整代码如下:

                #include <stdio.h>
                #include <math.h>
                #include <iostream>
                using namespace std;
                int main()
                {
                	double x1,x2;
                	double a,b,c;
                    cin >> a >> b >> c;
                    if ((b * b - 4 * a * c) < 0)
                    {
                        cout<<"No answer!";
                    }
                    else
                    {
                        if((b * b - 4 * a * c) == 0)
                        {
                        	x1 = -1 * (b / (2 * a));
                            printf("X1=X2=%.5lf\n",x1);
                        }
                        else
                        {
                        	x1 = (-b + sqrt(b*b - 4*a*c))/(2*a);
                        	x2 = (-b - sqrt(b*b - 4*a*c))/(2*a);
                            if(x1 > x2)
                            {
                                swap(x1,x2);
                            }
                            printf("x1=%.5lf;x2=%.5lf\n",x1,x2);
                        }
                    }
                
                }
                
                • -1
                  @ 2022-2-9 11:14:53

                  #include #include <math.h> #include using namespace std; int main() { double x,y,a,b,c; cin>>a>>b>>c; if (a==0) { cout<<"No answer!"; return 0; } x=(sqrt(bb-4ac)-b)/(2a); y=(-sqrt(bb-4ac)-b)/(2a); if (x>y){ swap(x,y); } if (fabs(x-y)<1e-6) { cout<<"x1=x2="<<fixed<<setprecision(5)<<x<<endl; } else { cout<<"x1="<<fixed<<setprecision(5)<<x<<";x2="<<fixed<<setprecision(5)<<y<<endl; } }

                  • -1
                    @ 2022-1-7 10:57:41
                    #include <stdio.h>
                    #include <math.h>
                    #include <iostream>
                    using namespace std;
                    int main()
                    {
                    	double a,b,c;
                        cin >> a >> b >> c;
                        if (a==0)
                        {
                            cout<<"No answer!";
                        }
                        else
                        {
                            double x1,x2;
                            x1 = (-b + sqrt(b*b - 4*a*c))/(2*a);
                            x2 = (-b - sqrt(b*b - 4*a*c))/(2*a);
                            if( fabs(x1-x2)< 1e-6)
                            {
                                printf("X1=X2=%.5lf\n",x1);
                            }
                            else
                            {
                                if(x1 > x2)
                                {
                                    swap(x1,x2);
                                }
                                printf("x1=%.5lf;x2=%.5lf\n",x1,x2);
                            }
                        }
                    
                    }
                    
                    • -1
                      @ 2022-1-7 10:46:55
                      #include <iostream>
                      #include <math.h>
                      #include<iomanip>
                      using namespace std;
                      int main()
                      {
                          double x,y,a,b,c;
                          cin>>a>>b>>c;
                          if (a==0)
                          {
                              cout<<"No answer!";
                              return 0;
                          }
                          x=(sqrt(b*b-4*a*c)-b)/(2*a);
                          y=(-sqrt(b*b-4*a*c)-b)/(2*a);
                          if (x>y){
                              swap(x,y);
                          }
                          if (fabs(x-y)<1e-6)
                          {
                              cout<<"x1=x2="<<fixed<<setprecision(5)<<x<<endl;
                          }
                          else
                          {
                              cout<<"x1="<<fixed<<setprecision(5)<<x<<";x2="<<fixed<<setprecision(5)<<y<<endl;
                          }
                      }
                      
                      • -3
                        @ 2024-6-15 20:13:28

                        #include<bits/stdc++.h> using namespace std; int main(){ for(long long i=0;i<=514514;i++){ cout<<"1111111111111111111111111111111111111111111111111"; } return 0; }

                        • 1

                        信息

                        ID
                        876
                        时间
                        1000ms
                        内存
                        256MiB
                        难度
                        6
                        标签
                        递交数
                        743
                        已通过
                        201
                        上传者