2 条题解
-
1
匪肠的煎蛋:
#include<bits/stdc++.h> using namespace std; int main(){ double a,b,c;//没double(float/...)0分! cin>>a>>b>>c; if(a==0||b*b-4*a*c<0){ cout<<"No root."; return 0; } double maxx=(-b+sqrt(b*b-4*a*c))/(2*a); double minn=(-b-sqrt(b*b-4*a*c))/(2*a); /* if(maxx<minn){ int d=maxx; maxx=minn; minn=d; } */ //因为所有测试点中,a、b、c均没有负数情况,所以没有这串代码也能侥幸AC😃😃😃 if(maxx!=minn) printf("x1=%.2lf\nx2=%.2lf",maxx,minn); //cout<<"x1="<<maxx<<"\nx2="<<minn; else printf("x=%.2lf",minn);//minn改成maxx也行 //cout<<"x="<<minn(换成maxx也可以) return 0; }备注:\n可以换成endl
最重要的一点:一元二次方程公式
-
1
#include <iostream> #include <cmath> #include <iomanip> using namespace std; int main() { double a,b,c; cin>>a>>b>>c; double delta=b*b-4*a*c; if (delta>0) { double x1=(-b+sqrt(delta))/(2*a); double x2=(-b-sqrt(delta))/(2*a); cout<<fixed<<setprecision(2); cout<<"x1="<<x1<<endl; cout<<"x2="<<x2<<endl; } else if (delta==0) { double x=-b/(2*a); cout<<fixed<<setprecision(2); cout<<"x="<<x<< endl; } else { cout<<"No root."<< endl; } return 0; }
- 1
信息
- ID
- 1499
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 5
- 标签
- 递交数
- 36
- 已通过
- 16
- 上传者