第八届山东ACM省赛F题-quadratic equation

这个题困扰了我长达1年多,终于在今天下午用两个小时理清楚啦

要注意的有以下几点:

1.a=b=c=0时 因为x有无穷种答案,所以不对

2.注意精度问题

3.b^2-4ac<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
 1 #include <iostream>
 2 #include <math.h>
 3
 4 using namespace std;
 5
 6 double _abs(double a)
 7 {
 8     if (a < 0)
 9         return -a;
10     return a;
11 }
12
13 int main()
14 {
15     ios::sync_with_stdio(false);
16     int t;
17     cin >> t;
18     while (t--)
19     {
20         double a, b, c;
21         cin >> a >> b >> c;
22         if (!a && !b)
23         {
24             if (!c)
25                 cout << "NO" << endl;
26             else
27                 cout << "YES" << endl;
28         }
29         else if (!a && b)
30         {
31             if (_abs(c/b - (int)(c/b)) > 0.0000001)
32                 cout << "NO" << endl;
33             else
34                 cout << "YES" << endl;
35         }
36         else
37         {
38             if ((b * b - 4 * a * c) >= 0)
39             {
40                 double x1 = (-b + sqrt(b*b - 4 * a*c)) / (2 * a);
41                 double x2 = (-b - sqrt(b*b - 4 * a*c)) / (2 * a);
42                 //cout << x1 << ends << x2 << endl;
43                 if (_abs(x1 - (int)x1) > 0.0000001 || _abs(x2 - (int)x2) > 0.0000001)
44                     cout << "NO" << endl;
45                 else
46                     cout << "YES" << endl;
47             }
48             else
49                 cout << "YES" << endl;
50         }
51     }
52
53     return 0;
54 }

原文地址:https://www.cnblogs.com/qq965921539/p/9360727.html

时间: 2024-10-15 07:57:43

第八届山东ACM省赛F题-quadratic equation的相关文章

[2012山东ACM省赛] Pick apples (贪心,全然背包,枚举)

Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描写叙述 Once ago, there is a mystery yard which only produces three kinds of apples. The number of each kind is infinite. A girl carrying a big bag comes into the yard. She is so surprised because s

sdut 2603 Rescue The Princess(算是解析几何吧)(山东省第四届ACM省赛A题)

题目地址:sdut 2603 Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the princess, a prince who wanted to marry the princess

[2012山东ACM省赛] n a^o7 !(模拟,字符替换)

n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you will step into a distinctive battleground which is full of sweet and happiness. If you want to win the battle, you must do warm-up according to my inst

Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)

Time Limit: 5000MS Memory limit: 65536K 题目描写叙述 Haveyou ever played a popular game named "Fruit Ninja"? Fruit Ninja (known as Fruit Ninja HD on the iPad and Fruit Ninja THD for NvidiaTegra 2 based Android devices) is a video game developed by Hal

[2013山东ACM省赛] Alice and Bob

Alice and Bob Time Limit: 1000MS Memory limit: 65536K 题目描述 Alice and Bob like playing games very much.Today, they introduce a new game. There is a polynomial like this: (a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1). Then Alice ask

[2013山东ACM省赛] The number of steps (概率DP,数学期望)

The number of steps Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Mary stands in a strange maze, the maze looks like a triangle(the first layer have one room,the second layer have two rooms,the third layer have three rooms -). Now she st

第十届山东省acm省赛补题(2)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4124 L Median Time Limit: 1 Second      Memory Limit: 65536 KB Recall the definition of the median of  elements where  is odd: sort these elements and the median is the -th largest element.

ZZUOJ - 1245 - 寻找幸福的小L ( 郑州大学第八届ACM大学生程序设计竞赛正式赛F题)

1245: 寻找幸福的小L Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 60  Solved: 14 [Submit][Status][Web Board] Description 小L最近看上了一个女同学叫小A,但是小A是个高冷的姑娘,所以她给小L出了个难题,她给小L留下了一张纸条,上面只有一个坐标,和一个时间,所以小L需要在规定时间找到这个坐标的地点,并在那个时间到哪个地点等待小A,但是很无奈,小L不是一个地理通,所以他找到了小A的室友,想

ZZUOJ-1194-ARM立即数寻址 (郑州大学第七届ACM大学生程序设计竞赛正式赛F题)

Problem F: ARM立即数寻址 Time Limit: 4 Sec  Memory Limit: 128 MB Submit: 53  Solved: 12 [Submit][Status][Web Board] Description 在ARM处理器立即数寻址方式中,立即数是由一个8位的无符号常数(大于等于0,小于等于0xff),先扩展为32位,然后循环右移偶数位得到.所以类似0x101,0x102,0xFF1,0xFF04,0x8000007F等都是无效的立即数,而像0xFF,0x3