QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#423463#7110. Kuririn MIRACLEucup-team3215Compile Error//C++201.7kb2024-05-28 03:10:562024-05-28 03:10:56

Judging History

你现在查看的是最新测评结果

  • [2024-05-28 03:10:56]
  • 评测
  • [2024-05-28 03:10:56]
  • 提交

answer

#include <array>
#include <iostream>

using namespace std;

double midpoint(double r, double d, double mt, double h, auto& deriv) {
  double x = 0, y = 0, t = 0, c = 1;
  auto mp = [&] {
    auto [dx, dy] = deriv(x, y, t);
    return deriv(x + dx * h * c / 2, y + dy * h * c / 2, t + h * c / 2);
  };
  while (1) {
    // cout << t << ' ' << x << ' ' << y << ' ' << (x - t - 2 * r) * (x - t - 2 * r) + y * y - 4 * r * r << '\n';
    if (t >= mt) return 1. / 0;
    if (c < 1e-9) return t + sqrt((x - d) * (x - d) + y * y) / 2;
    auto [dx, dy] = mp();
    auto nx = x + dx * h * c, ny = y + dy * h * c, nt = t + h * c;
    auto [ndx, ndy] = deriv(nx, ny, nt);
    if (ndy < 0 && nx - ny / ndy * ndx < d) { c /= 2; continue; }
    x = nx, y = ny, t = nt;
    double coef = sqrt(((x - t - 2 * r) * (x - t - 2 * r) + y * y) / (4 * r * r));
    if (abs(coef - 1) > 1e-12) {
      x = (t + 2 * r) + (x - t - 2 * r) / coef;
      y = y / coef;
    }
  }
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  for (int tc = (cin >> tc, tc); tc--; ) {
    double v, r, d; cin >> v >> r >> d;
    auto deriv = [&](double x, double y, double t) -> array<double, 2> {
      double dx = x - t - 2 * r;
      if (abs(dx) < y) {
        double r = -dx / y, rr = r * r;
        double ux = (rr + sqrt(3 * rr + 4)) / (1 + rr);
        return {ux, (ux - 1) * r};
      } else {
        double r = -y / dx, rr = r * r, d = sqrt(4 * rr + 3);
        double uy = (-r + (dx < 0? d: -d)) / (1 + rr);
        return {uy * r + 1, uy};
      }
    };
    cout.precision(20);
    double ans = d;
    if (d >= 7 * r) ans = min(ans, midpoint(r, d, d - 4 * r, (d - 4 * r) / 1e5, deriv));
    cout << ans / v << '\n';
  }
}

Details

answer.code: In function ‘double midpoint(double, double, double, double, auto:16&)’:
answer.code:14:28: warning: division by zero [-Wdiv-by-zero]
   14 |     if (t >= mt) return 1. / 0;
      |                         ~~~^~~
answer.code:15:30: error: there are no arguments to ‘sqrt’ that depend on a template parameter, so a declaration of ‘sqrt’ must be available [-fpermissive]
   15 |     if (c < 1e-9) return t + sqrt((x - d) * (x - d) + y * y) / 2;
      |                              ^~~~
answer.code:15:30: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
answer.code:21:19: error: there are no arguments to ‘sqrt’ that depend on a template parameter, so a declaration of ‘sqrt’ must be available [-fpermissive]
   21 |     double coef = sqrt(((x - t - 2 * r) * (x - t - 2 * r) + y * y) / (4 * r * r));
      |                   ^~~~
answer.code: In lambda function:
answer.code:37:27: error: ‘sqrt’ was not declared in this scope
   37 |         double ux = (rr + sqrt(3 * rr + 4)) / (1 + rr);
      |                           ^~~~
answer.code:40:45: error: ‘sqrt’ was not declared in this scope
   40 |         double r = -y / dx, rr = r * r, d = sqrt(4 * rr + 3);
      |                                             ^~~~
answer.code: In instantiation of ‘double midpoint(double, double, double, double, auto:16&) [with auto:16 = main()::<lambda(double, double, double)>]’:
answer.code:47:44:   required from here
answer.code:14:28: warning: division by zero [-Wdiv-by-zero]
   14 |     if (t >= mt) return 1. / 0;
      |                         ~~~^~~
answer.code:15:34: error: ‘sqrt’ was not declared in this scope
   15 |     if (c < 1e-9) return t + sqrt((x - d) * (x - d) + y * y) / 2;
      |                              ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:21:23: error: ‘sqrt’ was not declared in this scope
   21 |     double coef = sqrt(((x - t - 2 * r) * (x - t - 2 * r) + y * y) / (4 * r * r));
      |                   ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~