Equations
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 758 Accepted Submission(s): 350
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 a*X
2 + b*X + 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
Author
Mugurel Ionut Andreica
Source
Recommend
lcy
/*
思路:判断方程是否有解,特别注意一元方程中的几种特殊情况
*/
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--){
int a,b,c;
cin>>a>>b>>c;
if(a==0){ //一元一次方程
if(b==0){ //常数等式
if(c==0) //0=0情况
cout<<"INF"<<endl;
else
cout<<"0"<<endl; //0=c(c!=0)情况
}
else //bx=c
cout<<"1"<<endl;
}
else{ //二元一次方程
int sum=b*b-4*a*c;
if(sum>=0){
if(sum==0)
cout<<"1"<<endl;
else
cout<<"2"<<endl;
}
else
cout<<"0"<<endl;
}
}
return 0;
}