hdoj--5615--Jam's math problem(数学)(交叉相乘)
2016-03-15 17:50
357 查看
Total Submission(s): 861 Accepted Submission(s): 411
[align=left]Problem Description[/align]
Jam has a math problem. He just learned factorization.
He is trying to factorize ax2+bx+c
into the form of pqx2+(qk+mp)x+km=(px+k)(qx+m).
He could only solve the problem in which p,q,m,k are positive numbers.
Please help him determine whether the expression could be factorized with p,q,m,k being postive.
[align=left]Input[/align]
The first line is a number
T,
means there are T(1≤T≤100)
cases
Each case has one line,the line has 3
numbers a,b,c(1≤a,b,c≤100000000)
[align=left]Output[/align]
You should output the "YES" or "NO".
[align=left]Sample Input[/align]
2
1 6 5
1 6 4
[align=left]Sample Output[/align]
YES
NO
Hint
The first case turn $x^2+6*x+5$ into $(x+1)(x+5)$
[align=left]Source[/align]
BestCoder Round #70
我记得以前应该是这么做的,找出二次项系数跟常数项个子所有因子,然后组合,看是否可以组合产生一次项系数,,,本来以为会超时的,但是水过了 - - ||
Jam's math problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 861 Accepted Submission(s): 411
[align=left]Problem Description[/align]
Jam has a math problem. He just learned factorization.
He is trying to factorize ax2+bx+c
into the form of pqx2+(qk+mp)x+km=(px+k)(qx+m).
He could only solve the problem in which p,q,m,k are positive numbers.
Please help him determine whether the expression could be factorized with p,q,m,k being postive.
[align=left]Input[/align]
The first line is a number
T,
means there are T(1≤T≤100)
cases
Each case has one line,the line has 3
numbers a,b,c(1≤a,b,c≤100000000)
[align=left]Output[/align]
You should output the "YES" or "NO".
[align=left]Sample Input[/align]
2
1 6 5
1 6 4
[align=left]Sample Output[/align]
YES
NO
Hint
The first case turn $x^2+6*x+5$ into $(x+1)(x+5)$
[align=left]Source[/align]
BestCoder Round #70
我记得以前应该是这么做的,找出二次项系数跟常数项个子所有因子,然后组合,看是否可以组合产生一次项系数,,,本来以为会超时的,但是水过了 - - ||
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int a[10000+10],b[10000+10]; int main() { int t; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); int A,B,C; scanf("%d%d%d",&A,&B,&C); int cnt1,cnt2; cnt1=cnt2=0; for(int i=1;i<=sqrt(A);i++) if(A%i==0) a[cnt1++]=i; for(int i=1;i<=sqrt(C);i++) if(C%i==0) b[cnt2++]=i; int f=false; for(int i=0;i<cnt1;i++) { int p=a[i]; int q=A/a[i]; for(int j=0;j<cnt2;j++) { int k=b[j]; int m=C/b[j]; if(m*p+q*k==B) { f=true; break; } if(p*k+q*m==B) { f=true; break; } } if(f) break; } if(f) printf("YES\n"); else printf("NO\n"); } return 0; }
相关文章推荐
- 奇妙的数字--蓝桥杯
- equal() 与hashcode()之我理解
- 嵌入式
- 内部类的作用
- MarkdownPad 2 注册码 RSA私钥
- servlet-api-2.4.jar not loaded解决方法
- 选择器Selector的使用
- android 跟随手指移动的 view
- 本地音乐播放器(一)——简介篇
- solution Of Pat 1111. Online Map (30)
- 想成为前端工程师?希望读完这篇文章能对你有所帮助。
- linux 使用/proc文件系统 实现用户空间与内核模块之间通信
- 局域网无法访问vmware虚拟机WEB服务器解决办法
- 2013年五大主流浏览器 HTML5 和 CSS3 兼容性大比拼【转】
- yum install出错问题
- 关于serialVersionUID的说明
- 使用lua实现几个小算法
- css简写属性格式
- Struts2从一个action转到另一个action的两种方法
- Android 中 View 炸裂特效的实现分析