hdoj 5615 Jam's math problem【数学】【判断方程能否因式分解】

Jam's math problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 605    Accepted Submission(s): 299



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)
 

Source
BestCoder Round #70
 

求根的判别式  判断即可~

#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#define mem(a, b) memset(a, (b), sizeof(a))
#define Wi(a) while(a--)
#define Si(a) scanf("%d", &a)
#define Pi(a) printf("%d\n", (a))
#define INF 0x3f3f3f3f
#include<algorithm>
using namespace std;
double fun(double a, double b, double c)
{
	return b*b-4*a*c;
}
int main()
{
	int t; Si(t);
	Wi(t)
	{
		double a, b, c;
		scanf("%lf%lf%lf", &a, &b, &c);
		double f = fun(a, b, c);
		if(f < 0)  puts("NO");
		else{
			f = sqrt(f);
			int p = (int) (f);
			if(p*1.0 == f)	puts("YES");
			else  puts("NO");
		}
	}
	return 0;
}




你可能感兴趣的:(hdoj 5615 Jam's math problem【数学】【判断方程能否因式分解】)