結果
問題 | No.1179 Quadratic Equation |
ユーザー |
![]() |
提出日時 | 2020-08-21 23:18:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 745 bytes |
コンパイル時間 | 3,071 ms |
コンパイル使用メモリ | 192,712 KB |
最終ジャッジ日時 | 2025-01-13 06:35:09 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 |
ソースコード
#include <bits/stdc++.h>using namespace std;const int BUFFER_SIZE = 100;int main(){double a, b, c,d;double x1, x2;cin>>a>>b>>c;d = b * b - 4 * a * c;if(d >=0){ /* 判別式が正のとき、解を計算 */x1 = (fabs(b) + sqrt(d)) / (2.0 * a); /* 修正箇所 */if ( b >= 0.0 ) {x1 = -x1;}x2 = c / (a * x1);if(d==0) cout<<fixed<<setprecision(10)<<x1<<endl;else cout<<fixed<<setprecision(10)<<min(x1,x2)<<" "<<max(x1,x2)<<endl;}else{ /* 判別式が負のとき虚数解と表示 */cout<<"imaginary"<<endl;}return 0;}