title: Equations 数学 杭电1840
tags: [数学]

题目链接

Problem Description

All the problems in this contest totally bored you. And every time you get bored you like playing with quadratic equations of the form aX2 + bX + c = 0. This time you are very curious to know how many real solutions an equation of this type has.

Input

The first line of input contains an integer number Q, representing the number of equations to follow. Each of the next Q lines contains 3 integer numbers, separated by blanks, a, b and c, defining an equation. The numbers are from the interval [-1000,1000].

Output

For each of the Q equations, in the order given in the input, print one line containing the number of real solutions of that equation. Print “INF” (without quotes) if the equation has an infinite number of real solutions.

Sample Input

3
1 0 0
1 0 -1
0 0 0

Sample Output

1
2
INF

分析:

就是判断一个方程的跟的个数,首先应该明白的一点就是,如果要用(b^2-4ac)的值来判断的前提必须是这是一个一元二次方程(即a!=0),

如果a=0且b!=0,也就意味着这是一个一元一次方程,

如果a=0切b=0,如果c!=的话,是没有解的,c=0的话,是INF。

代码:

#include<stdio.h>  
int main()  
{  
    int s,a,b,c;  
    scanf("%d",&s);  
    while(s--)  
    {  
        scanf("%d%d%d",&a,&b,&c);  
          
        if(a==0 && b==0 && c==0)  
            printf("INF\n");  
        if(a==0 && b==0 && c!=0)  
            printf("0\n");  
        else if(a==0 && b!=0)  
            printf("1\n");  
        else if(a!=0 && (b*b-4*a*c)>0)  
            printf("2\n");  
        else if(a!=0 && (b*b-4*a*c)==0)  
            printf("1\n");  
        else if(a!=0 && (b*b-4*a*c)<0)  
            printf("0\n");  
    }  
    return 0;  
}
posted on 2017-05-03 15:09  渡……  阅读(228)  评论(0编辑  收藏  举报