ACM 第八届山东省赛 F quadratic equation SDUT 3898
2017-05-17 21:44
633 查看
再次提交链接: 点击打开链接
Time Limit: 2000MS Memory Limit: 131072KB
Submit Statistic
With given integers a,b,c,
you are asked to judge whether the following statement is true: "For any x, if a⋅
![](http://www.sdutacm.org/image/3898.png)
+b⋅x+c=0,
then x is an integer."
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).
or each test case, output “
is true, or “
“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
考察的是离散数学的蕴含式的理解 P-->Q 只有P为1 Q为0是 结果才是0 其余情况全为1 所以
当P为0 即P 不成立时 结果依然是YES 这是一个坑
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <cstring>
using namespace std;
int main()
{
int T;
cin>>T;
int a,b,c;
int cont=1;
while(T--)
{
cin>>a>>b>>c;
int flag;
if(a==0)
{
if(b!=0)
{
if(c==0)
flag=1;
else if(c%b==0)
flag=1;
else
flag=0;
}
else
{
if(c==0)
flag=0;
else
flag=1;
}
}
else
{
int detal=b*b-4*a*c;
if(detal<0)
flag=1;
else
{
//printf("%d %lf\n",(int)sqrt(detal),sqrt(pow(sqrt(detal),2)));
if((int)sqrt(detal)==sqrt(pow(sqrt(detal),2)))
{
if((-b+(int)sqrt(detal))%(2*a)==0&&(-b-(int)sqrt(detal))%(2*a)==0)
flag=1;
else
flag=0;
}
else
flag=0;
}
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
quadratic equation
Time Limit: 2000MS Memory Limit: 131072KBSubmit Statistic
Problem Description
With given integers a,b,c,you are asked to judge whether the following statement is true: "For any x, if a⋅
![](http://www.sdutacm.org/image/3898.png)
+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
3 1 4 4 0 0 1 1 3 1
Example Output
YES YES NO
Hint
Author
“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)考察的是离散数学的蕴含式的理解 P-->Q 只有P为1 Q为0是 结果才是0 其余情况全为1 所以
当P为0 即P 不成立时 结果依然是YES 这是一个坑
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <cstring>
using namespace std;
int main()
{
int T;
cin>>T;
int a,b,c;
int cont=1;
while(T--)
{
cin>>a>>b>>c;
int flag;
if(a==0)
{
if(b!=0)
{
if(c==0)
flag=1;
else if(c%b==0)
flag=1;
else
flag=0;
}
else
{
if(c==0)
flag=0;
else
flag=1;
}
}
else
{
int detal=b*b-4*a*c;
if(detal<0)
flag=1;
else
{
//printf("%d %lf\n",(int)sqrt(detal),sqrt(pow(sqrt(detal),2)));
if((int)sqrt(detal)==sqrt(pow(sqrt(detal),2)))
{
if((-b+(int)sqrt(detal))%(2*a)==0&&(-b-(int)sqrt(detal))%(2*a)==0)
flag=1;
else
flag=0;
}
else
flag=0;
}
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
相关文章推荐
- 第八届ACM山东省赛 F quadratic equation
- ACM 第八届山东省赛 I Parity check SDUT 3901
- 山东省第八届acm大赛 F题 (SDUT 3898)
- 山东省第八届acm大赛 J题 (SDUT 3902)
- 山东省第八届acm大赛 G题 (SDUT 3899)
- 山东省第八届 ACM 省赛 sum of power(SDUT 3899)
- 2017年山东省第八届ACM大学生程序设计竞赛 C fireworks(sdut 3895) 逆元求组合数
- SDUT 3895 (山东省第八届ACM省赛C题) fireworks 杨辉三角+乘法逆元
- 2017年山东省第八届ACM大学生程序设计竞赛 B Quadrat(sdut 3894) 打表找规律
- SDUT 2157 Greatest Number (二分) 2010年山东省第一届ACM大学生程序设计竞赛
- 山东省第一届ACM省赛 B SDUT 2152 Balloons(简单的BFS)
- 2017年山东省第八届ACM竞赛总结
- 山东省第八届ACM省赛A.Return of the Nim
- ACM Sdut 2158 Hello World!(数学题,排序) (山东省ACM第一届省赛C题)
- 山东省第八届ACM省赛A题
- 山东省第八届ACM省赛 K 题 CF 解答(未完,待续)
- 山东省第一届ACM省赛 C SDUT 2153 Clockwise
- 第八届山东省ACM大学生程序设计竞赛个人总结
- 山东省第八届ACM省赛 I 题(Parity check)
- 山东省第八届ACM省赛 F 题(quadratic equation)