第八届山东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的小正方形,则加边的人得分.构成几个得几分,最终完成 ...
随机推荐
- 小程序二维码生成接口API
获取小程序码 我们推荐生成并使用小程序码,它具有更好的辨识度.目前有两个接口可以生成小程序码,开发者可以根据自己的需要选择合适的接口. 接口A: 适用于需要的码数量较少的业务场景 接口地址: http ...
- HTTP及XMLHTTP状态代码一览
(一) HTTP 1.1支持的状态代码 100 Continue 初始的请求已经接受,客户应当继续发送请求的其余部分 101 Switching Protocols 服务器将遵从客户的请求转换到另外一 ...
- CSS a 标签样式
CSS a 标签样式 a:LINK { color: red; } a:VISITED { color: yellow; } a:HOVER { color: green; } a:ACTIVE { ...
- IDEA启动缓慢且运行卡顿
最近在自己的机器上用IDEA时启动竟然要半分钟,且启动后索引操作居然还需要等待很久.并且每次通过IDEA执行JAVA项目在启动和关闭时都会发生卡顿.明明机器的配置不错,这是为啥呢? 这是因为为IDEA ...
- 用gdb+nm调试php c extension程序
.so写好了是给php脚本调用的,如果php脚本执行崩掉了,.so也只能在进程中饮恨而终,这时候php脚本调试经常用的echo, print_r, var_dump都派不上用场了.即使能打印一点儿错误 ...
- java用JDBC连接数据库的方式
//驱动位置String sDBDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";//连接数据库地址名字String ...
- iBase4j前端01_bootstrap-suggest json-server模拟后台数据、bootstrap-suggest环境搭建、开启bootstrap-suggest的post和put请求
1 准备 1.1 模拟的json数据 { "info": [ { "message": "信息", "value": [ ...
- 674. Longest Continuous Increasing Subsequence最长连续递增子数组
[抄题]: Given an unsorted array of integers, find the length of longest continuous increasing subseque ...
- Mac notes
1. Mac应用数据存放位置 ~/Library/Application Support/ 比如sublime text的应用数据~/Library/Application Support/Subli ...
- rpm遇到的坑-与VMP冲突
rpm遇到的坑-与VMP冲突 摘自:https://blog.csdn.net/shijichao2/article/details/78797586 2017年12月13日 22:29:21 阅读数 ...