12 条题解

  • 2
    @ 2024-11-8 13:05:46

    #include<bits/stdc++.h> using namespace std; int main() { double a,b,c,d,x,y; cin>>a>>b>>c; d=sqrt(bb-4ac); x=(-b+d)/(2.00a); y=(-b-d)/(2.00*a); if(x>y) { cout<<fixed<<setprecision(2)<<y<<" "<<x; } else { cout<<fixed<<setprecision(2)<<x<<" "<<y; } return 0; }

    • 1

      思路

      求根公式:

      x1,2=b±b24ac2ax_{1,2}=\frac{-b \pm \sqrt{b^2-4ac}}{2a}

      建议不要定义 x1 之类的全局变量,极有可能出错!!!

      code

      #include<bits/stdc++.h>
      using namespace std;
      double a,b,c;
      int main(){
      	cin>>a>>b>>c;
      	double x1=(-b+sqrt(b*b-4*a*c))/2.0/a,x2=(-b-sqrt(b*b-4*a*c))/2.0/a;
      	printf("%.2lf %.2lf",min(x1,x2),max(x1,x2));
      	return 0;
      }
      
      • 1
        @ 2024-11-8 16:55:35

        #include<bits/stdc++.h> using namespace std; int main() { double a,b,c,d,e,f; cin>>a>>b>>c; d=sqrt(bb-4ac); e=(-b+d)/(2a); f=(-b-d)/(2*a); cout<<fixed<<setprecision(2)<<min(e,f)<<" "<<max(e,f); return 0; }

        • 1
          @ 2024-11-8 13:11:08

          #include<bits/stdc++.h> using namespace std; int main() { double a,b,c,x1,x2,d; cin>>a>>b>>c; d=sqrt(bb-4ac); x1=(-b+d)/(2.00a); x2=(-b-d)/(2.00*a); if(x1<x2) { cout<<fixed<<setprecision(2)<<x1<<" "<<x2; } else { cout<<fixed<<setprecision(2)<<x2<<" "<<x1; } return 0; }

          • 1
            @ 2024-11-8 13:07:36
            #include<bits/stdc++.h>
            using namespace std;
            int main()
            {
            	double a,b,c,d,x1,x2;
            	cin>>a>>b>>c;
            	d=sqrt(b*b-4*a*c);
            	x1=(-b+d)/(2*a);
            	x2=(-b-d)/(2*a);
            	if(x1>x2)
            	{
            		cout<<fixed<<setprecision(2)<<x2<<" "<<x1<<endl;
            	}
            	else
            	{
            	    	cout<<fixed<<setprecision(2)<<x1<<" "<<x2<<endl;
            	}
            	return 0;
            }
            
            
            • 1

              记得用double

              • 0
                @ 2024-11-9 13:57:10

                #include<bits/stdc++.h> using namespace std; int main() { double a,b,c,d,x,y; cin>>a>>b>>c; d=sqrt(bb-4ac), x=(0-b+d)/(2a), y=(0-b-d)/(2*a); if(x<y){cout<<fixed<<setprecision(2)<<x<<" "<<y<<endl;} else{cout<<fixed<<setprecision(2)<<y<<" "<<x<<endl;} return 0; }

                • 0

                  #include<bits/stdc++.h> using namespace std; int main() { double a,b,c,d,e,f; cin>>a>>b>>c; d=sqrt(bb-4ac); if((bb-4ac)>=0){ e=(-b+d)/(2a); f=(-b-d)/(2a); if(e>=f) {cout<<fixed<<setprecision(2)<<f<<" "<<e; } if(e<f) {cout<<fixed<<setprecision(2)<<e<<" "<<f; } } }

                  • 0
                    @ 2023-12-25 21:32:24

                    #include<bits/stdc++.h> using namespace std; int main() { double a,b,c; double x1,x2,d; cin>>a>>b>>c; d=sqrt(bb-4.00ac); x1=(-b+d)/(2.00a); x2=(-b-d)/(2.00*a); cout<<fixed<<setprecision(2)<<x1<<' '<<x2<<' '<<endl; return 0; }

                    • 0
                      @ 2023-12-23 13:48:38

                      #include<bits/stdc++.h> using namespace std; int main() { double a,b,c; double x1,x2,d; cin>>a>>b>>c; d=bb-4ac; x1=(-b+d)/(2a); x2=(-b-d)/(2*a); cout<<fixed<<setprecision(2)<<x1<<" "<<x2<<endl; return 0; }

                      • -1
                        @ 2024-8-14 10:25:04

                        aasds

                        • -5
                          @ 2023-12-24 13:43:08
                          1. #include<bits/stdc++.h> using namespace std; int main() { double a,b,c; double x1,x2,d; cin>>a>>b>>c; d=bb-4.00ac; x1=(-b+d)/(2.00a); x2=(-b-d)/(2.00*a); cout<<fixed<<setprecision(2)<<x1<<" "<<x2<<endl; return 0; }
                          • 1

                          信息

                          ID
                          20
                          时间
                          1000ms
                          内存
                          256MiB
                          难度
                          7
                          标签
                          递交数
                          338
                          已通过
                          73
                          上传者