結果
| 問題 |
No.955 ax^2+bx+c=0
|
| コンテスト | |
| ユーザー |
yuruhiya
|
| 提出日時 | 2020-05-29 23:49:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,035 bytes |
| コンパイル時間 | 2,532 ms |
| コンパイル使用メモリ | 198,032 KB |
| 最終ジャッジ日時 | 2025-01-10 18:31:47 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 122 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
optional<vector<long double>> QuadraticEquation(long long a, long long b, long long c) {
long double A = a, B = b, C = c;
if (a == 0 && b == 0 && c == 0) {
return nullopt;
} else if (a == 0 && b == 0) {
return vector<long double>{};
} else if (a == 0) {
return vector{ -(C / B) };
} else {
long long d = b * b - 4 * a * c;
long double D = static_cast<long double>(d);
if (d < 0) {
return vector<long double>{};
} else if (d == 0) {
return vector{ -B / (2 * A) };
} else {
long double ans1 = 0, ans2 = 0;
if (b > 0) {
ans1 = (-B - sqrt(D)) / (2 * A);
} else {
ans1 = (-B + sqrt(D)) / (2 * A);
}
ans2 = (C / A) / ans1;
return vector{ min(ans1,ans2),max(ans1,ans2) };
}
}
}
int main() {
long long a, b, c;
cin >> a >> b >> c;
auto ans = QuadraticEquation(a, b, c);
cout << fixed << setprecision(16);
if (!ans) {
cout << -1 << endl;
} else {
cout << ans->size() << endl;
for (auto i : *ans) {
cout << i << endl;
}
}
}
yuruhiya