結果
| 問題 |
No.955 ax^2+bx+c=0
|
| コンテスト | |
| ユーザー |
t33f
|
| 提出日時 | 2019-12-18 09:56:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,161 bytes |
| コンパイル時間 | 531 ms |
| コンパイル使用メモリ | 77,372 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-07 00:37:14 |
| 合計ジャッジ時間 | 2,903 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 120 RE * 2 |
ソースコード
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
double bs(int dir, double neg, double a, double b, double c, double eps) {
double pos = neg;
assert(a*neg*neg+b*neg+c<0);
while (a*pos*pos+b*pos+c<0) { pos += dir; dir *= 2; }
for (int i = 0; i < 1000; i++) {
double m = (pos + neg) / 2;
if (a*m*m+b*m+c < 0) neg = m;
else pos = m;
}
return (pos+neg)/2;
}
int main() {
long long a, b, c; cin >> a >> b >> c;
cout << setprecision(16);
if (a == 0) {
if (b == 0) {
if (c == 0) cout << "-1\n";
else cout << "0\n";
} else {
cout << "1\n" << -(double)c/b << endl;
}
} else {
if (a < 0) a = -a, b = -b, c = -c;
long long d = b * b - 4 * a * c;
if (d == 0) {
cout << "1\n" << -b/2.0/a << endl;
} else if (d < 0) {
cout << "0\n";
} else {
double v = -b/2.0/a,
x = bs(-1, v, a, b, c, 1e-11),
y = bs(1, v, a, b, c, 1e-11);
cout << "2\n" << x << endl << y << endl;
}
}
}
t33f