TopCoder

User's AC Ratio

100.0% (1/1)

Submission's AC Ratio

50.0% (1/2)

Tags

Description

小風在上數學課,老師出了一道一元二次方程式 $ax^ 2 + bx + c = 0$ 讓大家練習,可是懶惰的小風想請你幫他用程式解解看這道問題是否有實數解,請勤勞的你幫助懶惰的小風吧!

請在程式碼的第一行引入標頭檔 lib0597.h,並實作以下函數:

  • bool solve_quadratic(int a, int b, int c, double &x1, double &x2)
    • $a, b, c$:代表一元二次方程式 $ax^ 2 + bx + c = 0$ 的三個係數,保證滿足 $-10^ 5 \leq a, b, c, \leq 10^ 5$。
    • 此函數需回傳一個布林值 true/false,如果有實數解請回傳 true,否則請回傳 false
    • 如果有實數解,請將兩個實數解分別存在變數 $x_1$ 以及 $x_2$ 中,並且必須滿足 $x_1 \leq x_2$。
    • 如果有重根的話,請將 $x_1$ 及 $x_2$ 都設為重根的值。

注意請勿在你的程式碼宣告主函式 main() 以及進行任何輸入輸出的動作,否則將會發生不可預期的結果。

Input Format

本題沒有輸入,隨意輸入將會得到不可預期的結果。

Output Format

本題沒有輸出,隨意輸出將會得到不可預期的結果。

Sample Input 1

1 2 1

Sample Output 1

has solution: x1 = -1.000000, x2 = -1.000000

Sample Input 2

-1 3 3

Sample Output 2

has solution: x1 = 3.791288, x2 = -0.791288

Sample Input 3

1 3 3

Sample Output 3

does not have solution.

Hints

Problem Source

Subtasks

No. Testdata Range Constraints Score
1 0~2 範例測資 0
2 0~17 無額外限制 100

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 524288 65536 1 2
1 1000 524288 65536 1 2
2 1000 524288 65536 1 2
3 1000 524288 65536 2
4 1000 524288 65536 2
5 1000 524288 65536 2
6 1000 524288 65536 2
7 1000 524288 65536 2
8 1000 524288 65536 2
9 1000 524288 65536 2
10 1000 524288 65536 2
11 1000 524288 65536 2
12 1000 524288 65536 2
13 1000 524288 65536 2
14 1000 524288 65536 2
15 1000 524288 65536 2
16 1000 524288 65536 2
17 1000 524288 65536 2