結果
問題 | No.955 ax^2+bx+c=0 |
ユーザー |
|
提出日時 | 2019-12-18 04:11:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,409 bytes |
コンパイル時間 | 998 ms |
コンパイル使用メモリ | 89,248 KB |
最終ジャッジ日時 | 2025-01-08 12:17:50 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 120 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%lld%lld%lld", &a, &b, &c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <iostream> #include <math.h> #include <iomanip> using namespace std; constexpr long double kEps = 1E-20, nEps = 1E-12, kInf = 1E20; int main() { long long int a, b, c; scanf("%lld%lld%lld", &a, &b, &c); if (a == 0) { if (b == 0) { if (c == 0) printf("-1\n"); else printf("0\n"); } else printf("1\n%.20lf\n", (double)((long double)c / (long double) -b)); } else { if (a < 0) { a = -a; b = -b; c = -c; } long double ta(a), tb(b), tc(c), d, sa, sb, l, r, mid; d = b * b - 4 * a * c; if (b * b - 4 * a * c > 0) { cout << 2 << '\n'; l = -kInf; r = -tb / ta / 2 + kEps; for (int i = 0; i < 100000; i++) { mid = (l + r) / 2; if (a * mid * mid + b * mid + c > kEps) l = mid; else r = mid; } mid = (l + r) / 2; cout << setprecision(80) << mid << '\n'; sa = a * mid * mid + b * mid + c; //assert(-kEps < sa && sa < kEps); l = -tb / ta / 2 - kEps; r = kInf; for (int i = 0; i < 100000; i++) { mid = (l + r) / 2; if (a * mid * mid + b * mid + c > kEps) r = mid; else l = mid; } mid = (l + r) / 2; cout << setprecision(80) << mid << '\n'; sa = a * mid * mid + b * mid + c; //assert(-kEps < sa && sa < kEps); } else if (b * b - 4 * a * c < 0) printf("0\n"); else printf("1\n%.20lf\n", (double) (-tb / (ta * 2))); } }