1. 程式人生 > >LA 8043. ACM-ICPC World Finals 2017 E. Need for Speed

LA 8043. ACM-ICPC World Finals 2017 E. Need for Speed

+= ble -m i++ include algorithm min print pre

二分
LA上的題目居然和原題有差別!變成了多組數據
下面這個程序是按原題寫的

#include <iostream>
#include <cstdio>
#include <algorithm>

int main() {
  int n, t;
  std::cin >> n >> t;
  
  double d[1000], s[1000];
  for (int i = 0; i < n; i++)
    std::cin >> d[i] >> s[i];
  
  double l = -*std::min_element(s, s + n), r = 1001000
; while (l + 2e-10 <= r) { double mid = l + (r - l) / 2, t_ = 0; for (int i = 0; i < n; i++) t_ += d[i] / (s[i] + mid); if (t_ < t) r = mid; else l = mid; } printf("%.9lf\n", l); return 0; }

LA 8043. ACM-ICPC World Finals 2017 E. Need for Speed