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);

        }

    }

}

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.