第八届山东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
#include <iostream>
#include <math.h> using namespace std; double _abs(double a)
{
if (a < )
return -a;
return a;
} int main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--)
{
double a, b, c;
cin >> a >> b >> c;
if (!a && !b)
{
if (!c)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
else if (!a && b)
{
if (_abs(c/b - (int)(c/b)) > 0.0000001)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
else
{
if ((b * b - * a * c) >= )
{
double x1 = (-b + sqrt(b*b - * a*c)) / ( * a);
double x2 = (-b - sqrt(b*b - * a*c)) / ( * a);
//cout << x1 << ends << x2 << endl;
if (_abs(x1 - (int)x1) > 0.0000001 || _abs(x2 - (int)x2) > 0.0000001)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
else
cout << "YES" << endl;
}
} return ;
}
第八届山东ACM省赛F题-quadratic equation的更多相关文章
- 2019山东ACM省赛L题题解(FLOYD传递闭包的变形)
本题地址 https://cn.vjudge.net/contest/302014#problem/L Median Time Limit: 1 Second Memory Limit: 6 ...
- 2013年山东省赛F题 Mountain Subsequences
2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从 ...
- ACM-ICPC 2019南昌网络赛F题 Megumi With String
ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...
- 上海高校金马五校赛 F题:1 + 2 = 3?
链接:https://www.nowcoder.com/acm/contest/91/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言26214 ...
- [2011山东ACM省赛] Mathman Bank(模拟题)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/sr19930829/article/details/24187925 Mathman Bank ni ...
- 2016 acm香港网络赛 F题. Crazy Driver(水题)
原题网址:https://open.kattis.com/problems/driver Crazy Driver In the Linear City, there are N gates arra ...
- hihoCoder #1388 : Periodic Signal ( 2016 acm 北京网络赛 F题)
时间限制:5000ms 单点时限:5000ms 内存限制:256MB 描述 Profess X is an expert in signal processing. He has a device w ...
- 2013 ACM/ICPC 长春网络赛F题
题意:两个人轮流说数字,第一个人可以说区间[1~k]中的一个,之后每次每人都可以说一个比前一个人所说数字大一点的数字,相邻两次数字只差在区间[1~k].谁先>=N,谁输.问最后是第一个人赢还是第 ...
- 2013 ACM/ICPC 南京网络赛F题
题意:给出一个4×4的点阵,连接相邻点可以构成一个九宫格,每个小格边长为1.从没有边的点阵开始,两人轮流向点阵中加边,如果加入的边构成了新的边长为1的小正方形,则加边的人得分.构成几个得几分,最终完成 ...
随机推荐
- 【面试】D
昨天去了慕名已久的Dell面试(Dell自2015年退出了世界500强的评比),一面基本合格,二面基本没答上... 对公司的整体印象非常好(每个人桌上都有两台很大的显示器:9:00-15:30,如果能 ...
- 第六章 MySQL函数(待续)
············
- JavaScript高级程序设计学习
1.变量 变量使用var操作符定义,var message,定义一个message变量,可用来保存任何类型的变量.未经初始化的变量值为undifided: 如果没变量没有被var定义,那么被执行后会成 ...
- 解读show slave status 命令判断MySQL复制同步状态
解读show slave status 命令判断MySQL复制同步状态 1. show slave status命令可以显示主从同步的状态 MySQL> show slave status \G ...
- Tornado 高并发源码分析之五--- IOLoop 对象
IOLoop主要工作 1.将TCPServer 注册到 IOLoop 的事件记到 _handlers 字段,同时注册 READ 和 ERROR 事件到 epoll 2.IOLoop 启动一个大循环,负 ...
- 如何编写Word文档 多级编号
每次都忘 选择这个带标题的 这样可以根据标题来指定分级
- codeforce453DIV2——D. GCD of Polynomials
题意 给出n(1–150). 输出两个多项式A,B从常数到最高次的系数,使得对两个多项式求gcd时,恰好经过n步得到结果. 多项式的gcd一步是指(A(x),B(x))变成(B,A mod B)的过程 ...
- (三)maven出错记录
此处因为是自己做的所以文笔带过,简单描述下 1\首先是jsp页面报错,缺少必要的servletx依赖jar包,需要在pom中配置 <dependency><groupId>ja ...
- C++——STL之vector, list, deque容器对比与常用函数
STL 三种顺序容器的特性对比: vector 可变数组,内存空间是连续的,容量不会进行缩减.支持高效随机存取,即支持[]和at()操作.尾部插入删除效率高,其他位置插删效率较低: list 双向链表 ...
- SaeStorage使用示例
新浪SAE官方地址:http://apidoc.sinaapp.com/sae/SaeStorage.html SaeStorage的代码详细:http://apidoc.sinaapp.com/__ ...