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

      

  • 相关阅读:
    报数游戏
    Dynamics CRM 2013 初体验(2):UI
    Lucene.net常见功能实现知识汇总
    hdu 1853 最小费用流好题 环的问题
    MessagerService总结
    [置顶] Android EditText/TextView使用SpannableString显示复合文本
    MySQL Dll语句
    JavaScript表单验证
    intellij—idea14 注冊机
    OL记载Arcgis Server切片
  • 原文地址:https://www.cnblogs.com/bhd123/p/10310933.html
Copyright © 2011-2022 走看看