CF1076C Meme Problem 数学
Try guessing the statement from this picture:
You are given a non-negative integer d
. You have to find two non-negative real numbers a and b such that a+b=d and a⋅b=d
.
Input
The first line contains t
(1≤t≤103
) — the number of test cases.
Each test case contains one integer d
(0≤d≤103)
.
Output
For each test print one line.
If there is an answer for the i
-th test, print "Y", and then the numbers a and b
.
If there is no answer for the i
-th test, print "N".
Your answer will be considered correct if |(a+b)−a⋅b|≤10−6
and |(a+b)−d|≤10−6
.
Example
Input
Copy
7 69 0 1 4 5 999 1000
Output
Copy
Y 67.985071301 1.014928699 Y 0.000000000 0.000000000 N Y 2.000000000 2.000000000 Y 3.618033989 1.381966011 Y 997.998996990 1.001003010 Y 998.998997995 1.001002005
题意:求两个实数 a,b 满足 a+b==d&&a*b==d;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 400005
#define inf 0x3f3f3f3f
#define INF 9999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }
/*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/
ll qpow(ll a, ll b, ll c) {
ll ans = 1;
a = a % c;
while (b) {
if (b % 2)ans = ans * a%c;
b /= 2; a = a * a%c;
}
return ans;
}
int T;
int d;
int main()
{
//ios::sync_with_stdio(0);
rdint(T);
while (T--) {
rdint(d);
if (d*d < 4 * d)cout << "N" << endl;
else {
double a = 1.0*(d + sqrt(d*d - 4 * d)) / (2.0);
double b = 1.0*d - a;
cout << "Y" << ' ';
printf("%.9lf %.9lf\n", 1.0*a, 1.0*b);
}
}
return 0;
}