結果

問題 No.1179 Quadratic Equation
ユーザー otamay6otamay6
提出日時 2020-08-21 22:41:11
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 378 bytes
コンパイル時間 57 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-23 06:14:48
合計ジャッジ時間 2,029 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
12,288 KB
testcase_01 AC 90 ms
12,288 KB
testcase_02 AC 90 ms
12,288 KB
testcase_03 AC 91 ms
12,160 KB
testcase_04 AC 90 ms
12,160 KB
testcase_05 AC 90 ms
12,416 KB
testcase_06 AC 90 ms
12,288 KB
testcase_07 AC 91 ms
12,160 KB
testcase_08 AC 90 ms
12,416 KB
testcase_09 AC 91 ms
12,288 KB
testcase_10 WA -
testcase_11 AC 92 ms
12,416 KB
testcase_12 AC 92 ms
12,288 KB
testcase_13 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:18: warning: `+' after local variable or literal is interpreted as binary operator
Main.rb:18: warning: even though it seems like unary operator
Main.rb:10: warning: assigned but unused variable - c
Syntax OK

ソースコード

diff #

$a,$b,$c = gets.split.map(&:to_i)

d = $b*$b - 4*$a*$c
if  d< 0 then
    puts "imaginary"
    return
end
a= $a.to_f
b=$b.to_f
c=$c.to_f
mid = -b/(2*a)
if d==0 then
    puts mid
    return
end

def f(x)
   return $a*x*x + $b*x +$c
end

l = -1e9
r = mid
3000.times do
    m = (l+r)/2
    if f(m) < 0 then r=m
    else l = m
    end
end
x1 = l
x2 = mid + (mid-l)
puts "#{x1} #{x2}"
0