I。quadratic equation 山东第八届省赛

quadratic equation

Time Limit: 2000MS Memory Limit: 131072KB
Problem Description

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

Example Input
3
1 4 4
0 0 1
1 3 1
Example Output
YES
YES
NO

blablabla:明明是道挺水的题   做的我怎么就这样了呢。。。做题最怕的就是没自信了吧
我是个怎样的人呢 这是我经常想的东西吧
回归正题,刚开始是分别列出满足和不满足的情况 后来发现总容易考虑不周,干脆就找其中一个的情况
这和离散有不小关系 先是那个如果前提不成立 那么命题也是真的。。然后就是0 0 0的坑。。。
这个真的是被队友带了节奏  我还不思考  唉
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main()
{
    int T;
    int i,j;
    int a,b,c;
    double x1,x2;
    while(cin>>T)
    {
        while(T--)
        {
            int flag=0;
            cin>>a>>b>>c;
            if(a==0&&b==0&&c==0)
            {
                flag=0;
            }
            else if(a==b&&b==0&&c!=0)
            {
                flag=1;
            }
            else if(a==0&&b!=0)
            {
                if((-c)%b==0)
                {
                    flag=1;
                }
            }
            else if(c==0&&a!=0)
            {
                if((-b)%a==0)
                {
                    flag=1;
                }
            }
            else if(b==0&&a!=0&&c<=0)
            {
                if(a!=0&&b==0&&c==0)
                {
                    flag=1;
                }
                else
                {
                    x1=(-c)*1.0/a;
                    x1=sqrt(x1);
                    if((int)x1==x1)
                    {
                        flag=1;
                    }
                }
            }
            else if(a!=0)
            {
                int dt=b*b-4*a*c;
                if(dt<0) flag=1;
                else if(dt>=0)
                {
                    x1=(-b+(double)sqrt(dt))*1.0/(2*a);
                    x2=(-b-(double)sqrt(dt))*1.0/(2*a);
                    if((int)x1==x1&&(int)x2==x2)
                    {
                        flag=1;
                    }
                }
            }
            if(flag)
            {
                printf("YES\n");
            }
            else printf("NO\n");
        }
    }
    return 0;
}



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值