結果

問題 No.955 ax^2+bx+c=0
ユーザー 🍮かんプリン
提出日時 2020-05-16 04:04:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,324 bytes
コンパイル時間 1,271 ms
コンパイル使用メモリ 159,704 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-19 20:22:57
合計ジャッジ時間 4,078 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 122
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	f.cpp
 *   @Author	kanpurin
 *   @Created	2020.05.16 04:04:07
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    long double a, b, c;
    cin >> a >> b >> c;
    if (a != 0) {
        if (b * b - 4 * a * c > 0) {
            cout << 2 << endl;
            long double x, y;
            if (b >= 0) {
                x = (-b - sqrtl(b * b - 4 * a * c)) / (2 * a);
                y = c/a/x;
            } else {
                x = (-b + sqrtl(b * b - 4 * a * c)) / (2 * a);
                y = c/a/x;
            }
            if (x < y) {
                cout << fixed << setprecision(20) << x << endl;
                cout << fixed << setprecision(20) << y << endl;
            } else {
                cout << fixed << setprecision(20) << y << endl;
                cout << fixed << setprecision(20) << x << endl;
            }
        } else if (b * b - 4 * a * c == 0) {
            cout << 1 << endl;
            cout << fixed << setprecision(20) << -b / (2 * a) << endl;
        } else {
            cout << 0 << endl;
        }
    } else if (b != 0) {
        cout << 1 << endl;
        cout << fixed << setprecision(20) << -c / b << endl;
    } else if (c != 0) {
        cout << 0 << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}
0