“浪潮杯”山东省第八届ACM大学生程序设计竞赛F

quadratic equation

Time Limit: 2000MS Memory Limit: 131072KB

Submit Statistic

Problem Description

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

判断是否有非整数解,如果有就是no,否则yes

当时做题的时候一直没有搞明白这个题,一直WA,0 0 1这个式子根本不成立,说明没有非整数解所以是yes

还有就是0 0 0 所有的数都符合这个式子 所以是no

其他的就分情况判断就行了

判断一元二次方程的整数解也有点套路 当时做题一直都是求出来之后double和int比较的

#include <iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<cmath>
using namespace std;
int main(){
    int a,b,c,t;
    double d;
    cin>>t;
    while(cin>>a>>b>>c)
    {
        bool flag=false;
        if(a==0&&b==0&&c!=0)
            flag=true;
        else if(a==0&&b==0&&c==0)
            flag=false;
        else if(a==0&&b!=0&&c!=0)
        {
            if(c%b==0)
                flag=true;
        }
        else if(a==0&&c==0&&b!=0)
            flag=true;
        else{
                d=b*b-4*a*c;
                int dd=sqrt(d);
                if(d<0)
                flag=true;
                else{
                    if(fabs(dd-sqrt(d))<1e-9)
                        if((-b+dd)%(2*a)==0&&(-b-dd)%(2*a)==0)
                            flag=true;
                }
            }
        if(flag==true)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
        }
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值