zoukankan      html  css  js  c++  java
  • 细节

    With given integers a,b,c, you are asked to judge whether the following statement is true: "For any x, if x2 +bx+c=0, then x is an integer."

    Input

    The first line contains only one integer T(1≤T≤2000), which indicates the number of test cases. 
    For each test case, there is only one line containing three integers a,b,c(−5≤a,b,c≤5).

    Output

    or each test case, output “YES” if the statement is true, or “NO” if not.

    Sample Input

    3
    1 4 4
    0 0 1
    1 3 1
    

    Sample Output

    YES
    YES
    NO


    题意:
    给你三个数,a,b,c问这三个数构成的一元二次方程有没有非整数根,(如果有根,则一定整数,如果命题成立,输出yes 否则输出no),没有根的情况为yes。

    #include <iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #define minn 1e-8
    using namespace std;
    
    int main()
    {
        int t,a,b,c,ans;
        double ans1;
        cin>>t;
        while(t--)
        {
            cin>>a>>b>>c;
            if(a==0)
            {
                if(b!=0)
                {
                    if(c%b!=0)
                        printf("NO
    ");
                    else
                        printf("YES
    ");
                }
                else
                {
                    if(c==0)
                        printf("NO
    ");
                    else
                        printf("YES
    ");
                }
            }
            else
            {
                double der=b*b-4*a*c;
                if(der<0)
                {
                    printf("YES
    ");
    
                }
                else
                {
                    double dd=sqrt(der);
                    int dd1=int(sqrt(der));
                    if(abs(dd1-dd)<minn&&((-b+dd1)%(2*a)==0&&(-b-dd1)%(2*a)==0))
                        printf("YES
    ");
                    else
                        printf("NO
    ");
                }
    
            }
    
        } return 0;
    }
    

      

  • 相关阅读:
    unitTest单元测试框架
    Day06_页面发布与课程管理
    Day05_RabbitMQ研究
    Day04_页面静态化
    Day04_freemarker
    Day03_CMS页面管理开发
    Java概述练习题
    01_语言概述
    00_编程入门
    德道经
  • 原文地址:https://www.cnblogs.com/bhd123/p/10310933.html
Copyright © 2011-2022 走看看