HDU-5615(Jam's math problem)(方程求解)

19 篇文章 0 订阅
15 篇文章 0 订阅

HDU-5615-Jam's math problem(方程求解)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 870    Accepted Submission(s): 415


Problem Description
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.
 

Input
The first line is a number T , means there are T(1T100) cases

Each case has one line,the line has 3 numbers a,b,c(1a,b,c100000000)
 

Output
You should output the "YES" or "NO".
 

Sample Input
  
  
2 1 6 5 1 6 4
 

Sample Output
  
  
YES NO
Hint
The first case turn $x^2+6*x+5$ into $(x+1)(x+5)$
 
感觉这道题有点坑,可能是我英语不太好吧,  p,q,m,k are positive numbers。 p,q,m,k 不应该是正数吗?可是按正数处理,样例都不满足。最后看了别人的题解才知道,当作整数处理。
一元二次方程的解:x1=(-b-sqrt(b*b-4*a*c))/(2*a)、x2=(-b+sqrt(b*b-4*a*c))/(2*a),
刚开始面对这道题也不知道要如何求解,最后看了同学的题解恍然大悟,而且方法很简单。
x1=(-1)*(k/p),x2=(-1)*(m/q).
即:(-1)*(k/p)=(-b-sqrt(b*b-4*a*c))/(2*a)(-1)*(m/q)=(-b+sqrt(b*b-4*a*c))/(2*a)
,因k、p、m、q是整数,(2*a)、-b也是整数只要sqrt(b*b-4*a*c)为整数就满足,输出YES,否则输出NO.
 
My  solution:

/*2016.3.15*/

#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	long long a,b,c,q,p,k,m,n,h;
	double j;
	scanf("%I64d",&n);
	while(n--)
	{
		scanf("%I64d%I64d%I64d",&a,&b,&c);
		j=b*b-4*a*c;
		//m=b*b-4*a*c;
		if(j>=0)
		{
			j=sqrt(j);//q=sqrt(m) 
			h=(int)j;//强制类型转换 
			if(j-h)//if(q*q!=m) 
			printf("NO\n");
			else
			printf("YES\n");
		}
		else
		printf("NO\n");
	}	
	return 0;
 } 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值