cable master

double a = INF; は、const INF: f64 = 1e18; で表現する

const N: i32 = 4;
const K: i32 = 11;
const L: [f64; 4] = [8.02, 7.43, 4.57, 5.39];
const INF: f64 = 1e18; 

fn C(x: f64) -> bool {
   let mut num = 0.0;
   for i in 0..N {
      num += L[i as usize] / x;
   }
   return num >= K.into();
}

fn main() {
   let mut lb: f64 = 0.0;
   let mut ub: f64 = INF;

   for i in 0..100 {
      let mid: f64 = (lb + ub) / 2.0;
      if (C(mid)) {
         lb = mid;
      } else {
         ub = mid;
      }
   }
   println!("{}", ub * 100.0 / 100.0);
}

Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.41s
Running `target/debug/basic`
2.3100000000006227