本文主要是介绍ACM 第八届山东省赛 F quadratic equation SDUT 3898,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
再次提交链接: 点击打开链接
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 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
Hint
Author
考察的是离散数学的蕴含式的理解 P-->Q 只有P为1 Q为0是 结果才是0 其余情况全为1 所以
当P为0 即P 不成立时 结果依然是YES 这是一个坑
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <cstring>using namespace std;int main()
{int T;cin>>T;int a,b,c;int cont=1;while(T--){cin>>a>>b>>c;int flag;if(a==0){if(b!=0){if(c==0)flag=1;else if(c%b==0)flag=1;elseflag=0;}else{if(c==0)flag=0;elseflag=1;}}else{int detal=b*b-4*a*c;if(detal<0)flag=1;else{//printf("%d %lf\n",(int)sqrt(detal),sqrt(pow(sqrt(detal),2)));if((int)sqrt(detal)==sqrt(pow(sqrt(detal),2))){if((-b+(int)sqrt(detal))%(2*a)==0&&(-b-(int)sqrt(detal))%(2*a)==0)flag=1;elseflag=0;}elseflag=0;}}if(flag)printf("YES\n");elseprintf("NO\n");}return 0;
}
这篇关于ACM 第八届山东省赛 F quadratic equation SDUT 3898的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!