Solution
由韦达定理得,因为 \(a + b = d\) 且 \(a \times b = d\),所以 \(a\),\(b\) 就是方程 \(x^2 - d \times x + d = 0\) 的实数根,只要判断方程有无实根就可以了。
Code
完整代码如下
#include <bits/stdc++.h>
using namespace std;
double d;
int main() {int T;scanf("%d", &T);while (T--) {scanf("%lf", &d);int delta = d * d - 4.0 * d;if (delta < 0.0) {puts("N");continue;} printf("Y ");double a = (d + sqrt(delta)) / 2.0, b = (d - sqrt(delta)) / 2.0;printf("%.9lf %.9lf\n", a, b);}return 0;
}