結果
問題 |
No.955 ax^2+bx+c=0
|
ユーザー |
|
提出日時 | 2020-04-17 21:18:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 1,218 bytes |
コンパイル時間 | 3,213 ms |
コンパイル使用メモリ | 204,404 KB |
最終ジャッジ日時 | 2025-01-09 19:40:18 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 122 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = int64_t; int main() { ll a,b,c; cin>>a>>b>>c; if (a==0) { if (b==0) { cout<<(c==0?-1:0)<<endl; } else { cout<<1<<endl; cout <<fixed<<setprecision(15)<< double(-c) / b << endl; } return 0; } ll d = b*b - 4*a*c; if (d < 0) { cout<<0<<endl; return 0; } else if (d == 0) { cout<<1<<endl; double a2 = 2.0 * a; cout <<fixed<<setprecision(15)<< double(-b) / a2 << endl; } else { cout<<2<<endl; if (c == 0) { vector<double> res; res.push_back(0); res.push_back(double(-b) / a); sort(begin(res), end(res)); for(auto&& v:res) { cout <<fixed<<setprecision(15)<<v<<endl; } return 0; } long double a2 = 2.0L * a; long double c2 = 2.0L * c; vector<long double> res; long double ldd = d; if (b < 0) { res.push_back(c2 / (-b + sqrt(ldd))); res.push_back((-b + sqrt(ldd)) / a2); } else { res.push_back(c2 / (-b - sqrt(ldd))); res.push_back((-b - sqrt(ldd)) / a2); } sort(begin(res), end(res)); for(auto&& v:res) { cout <<fixed<<setprecision(15)<<v<<endl; } } return 0; }