結果

問題 No.955 ax^2+bx+c=0
ユーザー ianCK
提出日時 2019-12-18 04:00:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,356 bytes
コンパイル時間 912 ms
コンパイル使用メモリ 90,684 KB
最終ジャッジ日時 2025-01-08 12:16:48
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 82 RE * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%lld%lld%lld", &a, &b, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <iomanip>
using namespace std;
constexpr long double kEps = 1E-16;
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 {
		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) {
			l = -d;
			r = d;
			for (int i = 0; i < 100000; i++) {
				mid = (l + r) / 2;
				if (mid * mid > d + kEps) r = mid;
				else if(mid * mid < d - kEps) l = mid;
				else break;
			}
			mid = (l + r) / 2;
			sa = (-tb + l) / ta / 2; 
			sb = (-tb - l) / ta / 2; 
			if (sa < sb) {
				cout << 2 << '\n';
				cout << setprecision(80) << sa << '\n';
				cout << setprecision(80) << sb << '\n';
			}
			else {
				cout << 2 << '\n';
				cout << setprecision(80) << sb << '\n';
				cout << setprecision(80) << sa << '\n';
			}
			sa = a * sa * sa + b * sa + c;
			assert(-kEps < sa && sa < kEps);
			sb = a * sb * sb + b * sb + c;
			assert(-kEps < sb && sb < kEps);
		}
		else if (b * b - 4 * a * c < 0) printf("0\n");
		else printf("1\n%.20lf\n", (double) (-tb / (ta * 2)));
		
	}
	
}
0