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 925 (Div. 3) 1931D. Divisible Pairs Solution

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

Powered by Blogger.