您的位置:首页 > 其它

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

2017-05-13 13:32 337 查看


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 t
1fff7
he 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比较的

[code]01
#include
<iostream>
02
#include<string.h>
03
#include<string>
04
#include<algorithm>
05
#include<stdio.h>
06
#include<cmath>
07
using
namespace
std;
08
int
main()
09
{
10
int
a,b,c,t;
11
double
d;
12
cin>>t;
13
while
(cin>>a>>b>>c)
14
{
15
bool
flag=
false
;
16
if
(a==0&&b==0&&c!=0)
17
flag=
true
;
18
else
if
(a==0&&b==0&&c==0)
19
flag=
false
;
20
else
if
(a==0&&b!=0&&c!=0)
21
{
22
if
(c%b==0)flag=
true
;
23
}
24
else
if
(a==0&&c==0&&b!=0)
25
flag=
true
;
26
else
{
27
d=b*b-4*a*c;
28
int
dd=
sqrt
(d);
29
if
(d<0)
30
flag=
true
;
31
else
{
32
   
if
(
fabs
(dd-
sqrt
(d))<1e-9)
33
if
((-b+dd)%(2*a)==0&&(-b-dd)%(2*a)==0)flag=
true
; 
34
}
35
}
36
if
(flag==
true
)
37
cout<<
"YES"
<<endl;
38
else
39
cout<<
"NO"
<<endl;
40
}
41
return
0;
42
}
43
44
/***************************************************
45
User
name: 战神
46
Result:
Accepted
47
Take
time: 4ms
48
Take
Memory: 204KB
49
Submit
time: 2017-05-12 16:38:47
50
****************************************************/
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐