結果
| 問題 |
No.955 ax^2+bx+c=0
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-17 21:18:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 1,196 bytes |
| コンパイル時間 | 2,843 ms |
| コンパイル使用メモリ | 198,812 KB |
| 最終ジャッジ日時 | 2025-01-09 19:40:34 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 122 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main() {
ll a,b,c;
cin>>a>>b>>c;
if (a==0) {
if (b==0) {
cout<<(c==0?-1:0)<<endl;
} else {
cout<<1<<endl;
cout <<fixed<<setprecision(15)<< double(-c) / b << endl;
}
return 0;
}
ll d = b*b - 4*a*c;
if (d < 0) {
cout<<0<<endl;
return 0;
} else if (d == 0) {
cout<<1<<endl;
double a2 = 2.0 * a;
cout <<fixed<<setprecision(15)<< double(-b) / a2 << endl;
} else {
cout<<2<<endl;
if (c == 0) {
vector<double> res;
res.push_back(0);
res.push_back(double(-b) / a);
sort(begin(res), end(res));
for(auto&& v:res) {
cout <<fixed<<setprecision(15)<<v<<endl;
}
return 0;
}
double a2 = 2.0 * a;
double c2 = 2.0 * c;
vector<double> res;
double ldd = d;
if (b < 0) {
res.push_back(c2 / (-b + sqrt(ldd)));
res.push_back((-b + sqrt(ldd)) / a2);
} else {
res.push_back(c2 / (-b - sqrt(ldd)));
res.push_back((-b - sqrt(ldd)) / a2);
}
sort(begin(res), end(res));
for(auto&& v:res) {
cout <<fixed<<setprecision(15)<<v<<endl;
}
}
return 0;
}