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

      

  • 相关阅读:
    find
    Spring 中——————ClassPathResource初学
    Cookie 、Session、Token的学习
    JAVA注解之实现原理
    JAVA注解---2
    JAVA注解————1
    函数式遍程----Function
    java 反射的学习实践2
    Spring AOP 之动态代理源码分析
    正则表达式之Pattern.MULTILINE Pattern.DOTALL
  • 原文地址:https://www.cnblogs.com/bhd123/p/10310933.html
Copyright © 2011-2022 走看看