Equations

 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1840

    ——每天在线,欢迎留言谈论。

题目大意:

   给你一个一元二次方程组,a(X^2) + b(X) + c = 0 。求X解的个数。

思路:

  分别讨论二次方程与一次方程的情况,再特殊处理下 a = b = c = 0 的情况。

感想:

  是时候该水水题了。

Java AC代码:

 1 import java.math.*;
 2 import java.util.Scanner;
 3 
 4 public class Main {
 5     static Scanner scn = new Scanner(System.in);
 6     
 7     public static void main(String[] args) {
 8         int t, a, b, c, answer;
 9         t = scn.nextInt();
10         while (t-- > 0) {
11             a = scn.nextInt();
12             b = scn.nextInt();
13             c = scn.nextInt();
14             answer = Tool.getAns(a, b, c);
15             if (answer == -1)
16                 System.out.println("INF");
17             else
18                 System.out.println(answer);
19         }
20         System.exit(0);
21     }
22 }
23 
24 class Tool {
25     public static int getAns(int a, int b, int c) {
26         if (a == 0) {
27             if (b == 0) {
28                 if (c == 0)
29                     return -1;
30                 else
31                     return 0;
32             }
33             return 1;
34         } else {
35             int  o = (int)Math.pow(b, 2) - 4 * a * c;
36             if (o < 0)
37                 return 0;
38             else if (o == 0)
39                 return 1;
40             else
41                 return 2;
42         }
43     }
44 }

2017-08-10 19:16:00

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!