標籤:util 一個 感想 ble import == port span pid
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 else18 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 else31 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 else41 return 2;42 }43 }44 }
2017-08-10 19:16:00
HDU 1840 Equations (簡單數學 + 水題)(Java版)