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): 196    Accepted Submission(s): 102


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 
解题思路:
题目大意就是给出二元一次函数式的a,b,c问该式子能否被因式分解,初中学的十字交叉法,暴力就行了。
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#define LL __int64
using namespace std;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        bool wc=false;
        LL a,b,c;
        scanf("%I64d%I64d%I64d",&a,&b,&c);
        if((b*b-4*a*c)<0)
        {
            printf("NO\n");
        } 
        else
        {
            LL i,j;
            for(i=1;i<=sqrt(a);i++)
            {
                for(j=1;j<=sqrt(c);j++)
                {
                    if(a%i==0&&c%j==0)
                    {
                        LL xx,yy,uu,ii;
                        xx=i,yy=a/i,uu=j,ii=c/j;
                        if((xx*ii+yy*uu)==b||(xx*uu+yy*ii)==b)
                        {
                            wc=true;
                            break;
                        }
                    }
                }
                if(wc==true)
                break;
            }
            if(wc==true)
            printf("YES\n");
            else
            printf("NO\n");
        }
    }
    return 0;
} 


你可能感兴趣的:(Math,hdoj)