端午节月赛-山东省第八届省赛 quadratic equation(多种情况,△的判断)
来源:互联网 发布:c 面向对象编程流程 编辑:程序博客网 时间:2024/06/07 13:45
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.
Example Input
31 4 40 0 11 3 1
Example Output
YESYESNO
题意:
告诉你整数a, b, c, 判断命题“如果a⋅+b⋅x+c=0,那么 x 为整数"是否为真命题。
思路:
就是解一元二次方程组,多了1、判断是否为整数, 2、命题逻辑的知识点
注意点:
1、判断△<0 时,命题成立;
2、等价命题“如果 x 不是整数,那么等式不成立”
3、要分别考虑a = 0, b = 0, c = 0时的情况。
#include <cstdio>#include <iostream>#include <map>#include <algorithm>#include <math.h>#include <queue>#include <string>#include <cstring>using namespace std;int main(){ int T; scanf("%d", &T); while( T --) { double a, b, c; double x1, x2; cin >> a >> b >> c; if(a != 0) { double d = b * b - 4 *a *c; //判断△是否小于0 if(d >= 0) { d = sqrt(d); x1 = -b +d; x1 /= 2 * a; x2 = -b -d; x2 /= 2 *a; } else x1 = x2 = 1; } else if(b != 0) { x1 = -c / b; x2 = -c / b; } else if(c != 0) { x1 = x2 = 1; } else x1 = x2 = -0.5; //cout << x1 <<x2; int n1 = ceil(x1); //判断整数的方法 int n2 = ceil(x2); //cout << n1 << n2 << endl; if(n1==x1 && n2 == x2) cout << "YES" << endl; else cout << "NO" << endl; } return 0;}
阅读全文
0 0
- 端午节月赛-山东省第八届省赛 quadratic equation(多种情况,△的判断)
- ACM 第八届山东省赛 F quadratic equation SDUT 3898
- 第八届ACM山东省赛 F quadratic equation
- 山东省第八届 ACM 省赛 quadratic equation (水、坑)
- 山东省第八届ACM省赛 F 题(quadratic equation)
- 山东省第八届 ACM 省赛 quadratic equation
- 端午节月赛-山东省第八届省赛 Parity check(找奇偶规律)
- 山东省第八届ACM省赛 F题 quadratic equation (详解)
- 山东省第八届ACM省赛F.quadratic equation
- I。quadratic equation 山东第八届省赛
- quadratic equation
- quadratic equation
- CF 530A(Quadratic equation-注意(-b+sqrt(Δ))/2a<(-b-sqrt(Δ))/2a的情况)[Picat]
- 算法提高 Quadratic Equation
- HAUTOJ quadratic equation
- 山东第八届acm大赛F题quadratic equation,山东理工oj 3898
- 端午节个人赛-山东省省赛 fireworks(杨辉三角形+组合数+逆元)
- F——quadratic equation
- CodeForces Round #417 E Solution:Nim博弈
- Spring_JSR 303标准的校验框架与SpringMVC际化、及校验字符串消息国际化
- UVa 1471 Defense Lines——LIS nlogn 算法变形
- CentOS 7 安装VirtualBox
- at24c08 E2PROM的I2C设备驱动实例——基于mini2440
- 端午节月赛-山东省第八届省赛 quadratic equation(多种情况,△的判断)
- 发送有序广播
- POJ2533 Longest Ordered Subsequence【最长上升子序列+DP】
- USACO 3.3.1 骑马修栅栏
- 【实训】第二周工作下
- 24.Spring_与Web应用整合
- WebRTC Part1
- Android drawable微技巧,你所不知道的drawable的那些细节
- 1056. Mice and Rice (25)