第八届山东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的小正方形,则加边的人得分.构成几个得几分,最终完成 ...
随机推荐
- 2014.9.30 Double转字符
(57.0/60.0).ToString("f2")="0.95" 等于 string.Format("{0:F2}",57.0/60)=& ...
- java自己写的简单聊天工具SimpleQQ感悟
Demo如下: 客户端: /* * 一个简单的QQ * 2013-8-1 * @李志杰 */ package SimpleQQ_Client; import java.awt.*; import ja ...
- Python 面向对象 (补充) , 反射 , 内置函数
面向对象中内置函数 issubclass方法: 检查第一个参数是否是第二个参数的子子孙孙类 返回 : 是一个布尔值 class Base(object): pass class Foo( ...
- 手机发烫是为何—— App 电量测试定位方法
为什么要做电量测试 随着移动互联网的快速发展,手机的实用性.娱乐性越来越强.日常使用中发现,安装了应用后,即使不怎么使用,电量也会消耗很快.但如果恢复出场设置充满电后,手机可以待机很长时间.真相只有一 ...
- clock函数返回负值~ (转)
使用clock() 函数来进行计时,时不时的返回一个很大的负数,怎么检查也检查不出错误,现在找出错误原因,给大家分享一下. 来源网页:http://kebe-jea.blogbus.com/logs/ ...
- Elasticsearch之插件介绍及安装
ES站点插件(以网页形式展现) 1.BigDesk Plugin (作者 Lukáš Vlček) 简介:监控es状态的插件,推荐![目前不支持2.x] 2.Elasticsearch Head Pl ...
- Vulkan Tutorial 10 图形管线
操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Visual Studio 2017 Introduction 通过接下来的章节,我们将会开启有关图形管线的话题,通过对图 ...
- python 中 print 函数用法总结
Python 思想: “一切都是对象!” 在 Python 3 中接触的第一个很大的差异就是缩进是作为语法的一部分,这和C++等其他语言确实很不一样,所以要小心 ,其中python3和python2中 ...
- ParallaxEffect
[ParallaxEffect] ParallaxEffect是一种用简单的2D贴图来模拟3D效果的简易方法.譬如一棵树,摄像机俯视时,当树远离摄像机时,树顶偏远,当树靠近,树顶偏近.苹果官方Adve ...
- 二,python第一个程序
1.命令窗口进入python安装目录 2. >>> 100+200 300 很简单吧,任何有效的数学计算都可以算出来. 如果要让Python打印出指定的文字,可以用print语句,然 ...