山东省第八届acm大赛 F题 (SDUT 3898)
来源:互联网 发布:ipad pdf阅读器 知乎 编辑:程序博客网 时间:2024/06/05 14:54
quadratic equation
Time Limit: 2000MS Memory Limit: 131072KB
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掉 离散数学中的蕴含式 只有当前件成立后件不成立时输出 "NO" 其他情况都输出 "YES" 本题就是 当方程有解并且解不为整数时输出 "NO" 其他情况输出 "YES"
1 1 1
1 0 0
0 0 1
0 1 1
比赛的时候试了各种情况 唯独没判断sqrt(b*b-4*a*c)是否为整数
AC代码:
#include<stdio.h>#include<cmath>int main (){ int t; scanf ("%d",&t); while (t--){ int a,b,c; scanf ("%d%d%d",&a,&b,&c); if (a==0&&b==0&&c==0){ printf ("NO\n"); continue; } if (a==0){ if(b!=0&&c!=0){ if((c%b)!=0){ printf ("NO\n"); continue; } } } else if (a!=0){ float temp=(b*b)-(4*a*c); if (temp>=0){ if ((int)sqrt(temp)!=sqrt(temp)){ printf ("NO\n"); continue; } else{ if ((-1*b-(int)sqrt(temp))%(2*a)!=0||(-1*b+(int)sqrt(temp))%(2*a)!=0){ printf ("NO\n"); continue; } } } } printf ("YES\n"); } return 0;}
0 0
- 山东省第八届acm大赛 F题 (SDUT 3898)
- 山东省第八届acm大赛 J题 (SDUT 3902)
- 山东省第八届acm大赛 G题 (SDUT 3899)
- 山东省第八届acm大赛 I题 (SDUT 3901)
- ACM 第八届山东省赛 F quadratic equation SDUT 3898
- 山东省第八届ACM省赛 F 题(quadratic equation)
- 山东省第八届ACM大赛I题题解
- 山东省第八届ACM省赛 F题 quadratic equation (详解)
- SDUT 3896 HEX 山东第八届ACM大赛D题(组合数学)
- 山东省第一届ACM省赛 F SDUT 2156 Fairy tale
- ACM 第八届山东省赛 J company SDUT 3902
- ACM 第八届山东省赛 I Parity check SDUT 3901
- SDUT 3895 (山东省第八届ACM省赛C题) fireworks 杨辉三角+乘法逆元
- SDUT 3893 (山东省第八届ACM省赛A题) Return of the Nim 博弈nim+威佐夫
- 山东第八届acm大赛F题quadratic equation,山东理工oj 3898
- 山东省第八届 ACM 省赛 sum of power(SDUT 3899)
- “浪潮杯”山东省第八届ACM大学生程序设计竞赛F
- 第八届ACM山东省赛 F quadratic equation
- 解决Linux内核生成uImage时Entry Point自动偏移64个字节
- 2017年省赛前最后一水 Problem I: ACM’s OCR II(只有你想不到!!!)
- static关键字:
- 2017年省赛前最后一水 Problem A: String
- jfinal拦截器配置
- 山东省第八届acm大赛 F题 (SDUT 3898)
- Ubuntu图形界面介绍和远程VNC连接
- Linux 漫谈开源许可证/红帽认证
- ModBus/TCP协议分析
- vlc分析之基础结构
- 山东省第八届acm大赛 J题 (SDUT 3902)
- [LeetCode]15.threeSum
- 山东省第八届acm大赛 G题 (SDUT 3899)
- USACO