結果

問題 No.1793 実数当てゲーム
ユーザー koba-e964koba-e964
提出日時 2021-12-25 12:01:04
言語 Rust
(1.77.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,351 bytes
コンパイル時間 1,357 ms
コンパイル使用メモリ 161,352 KB
実行使用メモリ 24,624 KB
平均クエリ数 2230.56
最終ジャッジ日時 2023-10-21 12:51:05
合計ジャッジ時間 4,665 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
24,624 KB
testcase_01 AC 26 ms
24,624 KB
testcase_02 AC 94 ms
24,624 KB
testcase_03 AC 96 ms
24,624 KB
testcase_04 AC 98 ms
24,624 KB
testcase_05 AC 91 ms
24,624 KB
testcase_06 AC 95 ms
24,624 KB
testcase_07 AC 92 ms
24,624 KB
testcase_08 AC 96 ms
24,624 KB
testcase_09 AC 95 ms
24,624 KB
testcase_10 AC 95 ms
24,624 KB
testcase_11 AC 95 ms
24,624 KB
testcase_12 AC 96 ms
24,624 KB
testcase_13 AC 99 ms
24,624 KB
testcase_14 AC 99 ms
24,624 KB
testcase_15 AC 93 ms
24,624 KB
testcase_16 AC 94 ms
24,624 KB
testcase_17 AC 93 ms
24,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

// https://yukicoder.me/problems/no/1793 (3.5)
// 対数の世界で二分探索する。ただし答えが 10^{-5} 以下であれば 10^{-5} と答えて良い。
fn main() {
    let t: usize = get();
    for _ in 0..t {
        let mut hi = 12.22e74f64.ln();
        let mut lo = 1.0e-6f64.ln();
        for _ in 0..24 {
            let mid = (hi + lo) / 2.0;
            let y = mid.exp();
            println!("? {}", y);
            let s = get_word();
            if s == "Yes" {
                lo = mid;
            } else if s == "No" {
                hi = mid;
            } else {
                panic!();
            }
        }
        println!("! {}", ((lo + hi) / 2.0).exp());
    }
}
0