Codeforces 1076C. Meme Problem Solution
hints :(a-b)^2=(a+b)^2-4*a*b
Solve in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE
///Islamic University,Bangladesh
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int d,i,n;
double a,b,r;
cin>>n;
while(n--)
{
cin>>d;
r=(d*d)-4*d;
if(r<0)
{
cout<<"N"<<endl;
}
else
{
a=(d+sqrt(d*d-4*d))/2;
b=(d-sqrt(d*d-4*d))/2;
cout<<"Y ";
printf("%.9lf %.9lf\n",a,b);
}
}
}
Solve in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE
///Islamic University,Bangladesh
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int d,i,n;
double a,b,r;
cin>>n;
while(n--)
{
cin>>d;
r=(d*d)-4*d;
if(r<0)
{
cout<<"N"<<endl;
}
else
{
a=(d+sqrt(d*d-4*d))/2;
b=(d-sqrt(d*d-4*d))/2;
cout<<"Y ";
printf("%.9lf %.9lf\n",a,b);
}
}
}
No comments