結果

問題 No.1179 Quadratic Equation
ユーザー otamay6otamay6
提出日時 2020-08-21 22:43:56
言語 Ruby
(3.3.0)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 455 bytes
コンパイル時間 47 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-23 06:15:49
合計ジャッジ時間 2,499 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

$a,$b,$c = gets.split.map(&:to_i)
if $a<0 then
    $a = -$a
    $b = -$b
    $c = -$c
end
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 sprintf("%10.16f",mid)
    return
end

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

l = -1e18
r = mid
300000.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