結果
問題 | No.1179 Quadratic Equation |
ユーザー | otamay6 |
提出日時 | 2020-08-21 22:43:56 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 207 ms / 2,000 ms |
コード長 | 455 bytes |
コンパイル時間 | 99 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-10-15 06:02:52 |
合計ジャッジ時間 | 2,664 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 |
コンパイルメッセージ
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
ソースコード
$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}"