HDU 1840 Equations (簡單數學 + 水題)(Java版)

來源:互聯網
上載者:User

標籤: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版)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.