Codeforces Meme Problem 数学问题

C. Meme Problem

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Try guessing the statement from this picture:

You are given a non-negative integer dd. You have to find two non-negative real numbers aa and bb such that a+b=da+b=d and a⋅b=da⋅b=d.

Input

The first line contains tt (1≤t≤1031≤t≤103) — the number of test cases.

Each test case contains one integer dd (0≤d≤103)(0≤d≤103).

Output

For each test print one line.

If there is an answer for the ii-th test, print "Y", and then the numbers aa and bb.

If there is no answer for the ii-th test, print "N".

Your answer will be considered correct if |(a+b)−a⋅b|≤10−6|(a+b)−a⋅b|≤10−6 and |(a+b)−d|≤10−6|(a+b)−d|≤10−6.

题目链接:http://codeforces.com/problemset/problem/1076/C

题意就不说了,一张图片说明了一切!

解题思路:a+b=d     a⋅b=d, 这两个式子联立db−b^2−d=0, 然后根据数学公式算出二次函数在什么情况下是否有解,算出Δ,也就是数学中的b^2-4ac,找出解的范围,容易得出当d等于0时a=b=0, 在0-4之间是没有解的,要是有解的话,直接算出就可以了

#include <bits/stdc++.h>
using namespace std ;
typedef long double ld ;
const int Maxn = 1000 + 10 ;

int main (){
    ios_base::sync_with_stdio(false) ;
    cin.tie(0) ;
    cout.tie(0) ;
    cout << fixed << setprecision(9) ;
    ld T;
    ld d ;
    cin >> T ;
    while (T--){
        cin >> d ;
        if (d == 0) {
            cout << "Y " << 0.0 << " " << 0.0 << endl ;
            continue ;
        }
        if (d < 4) {
            cout << "N" << endl ;
            continue ;
        }
        ld D = sqrt(d * ld (d - 4)) ;
        ld a = (d + D) / 2.0 ;
        ld b = (d - D) / 2.0 ;
        cout << "Y " << a << " " << b << endl ;
    }
    return 0 ;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值