首页 > ACM题库 > HDU-杭电 > HDU 1840 Equations-数论[解题报告] C++
2013
12-23

HDU 1840 Equations-数论[解题报告] C++

Equations

问题描述 :

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*X2 + b*X + c = 0. This time you are very curious to know how many real solutions an equation of this type has.

输入:

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].

输出:

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.

样例输入:

3
1 0 0
1 0 -1
0 0 0

样例输出:

1
2
INF

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1840

题意:给一个方程ax^2+bx+c==0的三个系数a、b、c。判定方程解的个数。

mark:除了利用判别式,还需要注意考虑非二次的情况。

代码:

# include <stdio.h>
 
 
 void work()
 {
     int a, b, c, delta ;
     scanf ("%d%d%d", &a, &b, &c) ;
     if (a==0)
         if (b == 0)
             if (c == 0) puts ("INF") ;
             else puts ("0") ;
         else puts ("1") ;
     else
         if (b*b > 4*a*c) puts ("2") ;
         else if (b*b == 4*a*c) puts ("1") ;
         else puts ("0") ;
 }
 
 
 int main ()
 {
     int T ;
     scanf ("%d", &T) ;
     while (T--)
         work() ;
     return 0 ;
 }

 

 

解题报告转自:http://www.cnblogs.com/lzsz1212/p/3300162.html


  1. 有两个重复的话结果是正确的,但解法不够严谨,后面重复的覆盖掉前面的,由于题目数据限制也比较严,所以能提交通过。已更新算法

  2. 博主您好,这是一个内容十分优秀的博客,而且界面也非常漂亮。但是为什么博客的响应速度这么慢,虽然博客的主机在国外,但是我开启VPN还是经常响应很久,再者打开某些页面经常会出现数据库连接出错的提示