当前位置: 代码迷 >> 综合 >> 2017年ACM第八届山东省赛F题:quadratic equation(离散数学蕴含式)- SDUT3898
  详细解决方案

2017年ACM第八届山东省赛F题:quadratic equation(离散数学蕴含式)- SDUT3898

热度:87   发布时间:2023-11-02 23:08:03.0

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.

Sample Input

3
1 4 4
0 0 1
1 3 1

Sample Output

YES
YES
NO

Hint

Source

“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)

解题感悟:这道题用到了离散数学中的知识,也就是蕴含式,前真后假为假,其余都是真。

#include<iostream>
#include<cmath>
using namespace std;
int main()
{int t,a,b,c,tmp;cin>>t;while(t--){cin>>a>>b>>c;tmp=b*b-4*a*c;if(a==0){if(b==0)if(c==0)  //解可以取任意值,显然不满足条件cout<<"NO"<<endl;elsecout<<"YES"<<endl;  //前件不成立else{if(c%b==0)  //解为整数cout<<"YES"<<endl;else  //解不是整数cout<<"NO"<<endl;}}else if(tmp<0)  //无解cout<<"YES"<<endl;else{double res=sqrt(1.0*tmp);if((-b+res)/(2*a)-(int)((-b+res)/(2*a))==0&&(-b-res)/(2*a)-(int)((-b-res)/(2*a))==0)  //两个解都是整数cout<<"YES"<<endl;elsecout<<"NO"<<endl;}}return 0;
}

  相关解决方案