山东省第八届 ACM 省赛 quadratic equation

Problem Description

With given integers a,b,c, you are asked to judge whether the following statement is true: “For any x, if  ax2+bx2+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.


Example Input

3
1 4 4
0 0 1
1 3 1


Example Output

YES
YES
NO


题意

给出 a,b,c ,判断  ax2+bx2+c=0  是否有非整数解,若有,输出 NO ,否则输出 YES 。


这道题做的时候我们做的时候就把这到题当成分类讨论的题 也就朝着这个方向去做 但是后来我们没能找出(0 0 0 )这个坑来,所以着重也没能做出来 后来补这道题的时候依然没能找出坑来 自己的代码过于杂乱 所以找了一个模板以便参考

AC 代码

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
using namespace std;
#include<queue>
#include<map>
#define eps (1e-8)

bool jud(int a,int b,int c)
{
    if(a==0)
    {
        if(b==0)
        {
            if(c==0)return false;   // 大坑在此
            return true;
        }
        else if(c%b==0)return true;
        return false;
    }
    double der=b*b-4*a*c;
    int s=(int)sqrt(der);
    if(der<0)return true;
    if(fabs(s-sqrt(der))<eps)
        if((-b+s)%(2*a)==0&&(-b-s)%(2*a)==0)return true;
    return false;
}

int main()
{
    int T;
    scanf("%d",&T);
    for(int i=0; i<T; i++)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        printf(jud(a,b,c)?"YES\n":"NO\n");
    }
    return 0;
}
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值