QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#163071#7110. Kuririn MIRACLEhos_lyricCompile Error//C++142.9kb2023-09-03 20:02:042023-09-03 20:02:05

Judging History

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

  • [2023-09-03 20:02:05]
  • 评测
  • [2023-09-03 20:02:04]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


using Double = double;
constexpr Double PI = acos(-1.0L);

/*
  x = V t + 2R (1 - cos(q))
  y = 2R sin(q)
  
  dx/dt = V + 2R sin(q) dq/dt
  dy/dt = 2R cos(q) dq/dt
  
  (2V)^2
  = (dx/dt)^2 + (dy/dt)^2
  = V^2 + 4R V sin(q) dq/dt + 4R^2 (dq/dt)^2
  
  dq/dt
  = (-2R V sin(q) + sqrt(4R^2 V^2 sin(q)^2 + 12R^2 V^2)) / (4R^2)
  = (V/2R) (-sin(q) + sqrt(sin(q)^2 + 3))
  
  dt (V/2R)
  = dq / (-sin(q) + sqrt(sin(q)^2 + 3))
  = dq (sin(q) + sqrt(sin(q)^2 + 3)) / 3
  
  \int[q] dq sin(q)
  = 1 - cos(q)
  
  \int[q] dq sqrt(sin(q)^2 + 3)
  = \int[q] dq sqrt(4 - cos(q)^2)
  = \int[q] dq 2 sqrt(1 - (1/2)^2 sin(q+PI/2)^2)
*/

Double V, R, D;

Double ans;
bool check(Double q) {
  Double t = 0.0;
  t += (1.0 - cos(q));
  t += 2.0 * (ellint_2(0.5, q + PI/2) - ellint_2(0.5, PI/2));
// cerr<<q<<": "<<t<<endl;
  t /= 3.0;
  t /= (V / (2*R));
  Double dx = D - (V * t + 2*R * (1.0 - cos(q)));
  Double dy = 0.0 - (2*R * sin(q));
  const Double e = sqrt(dx*dx + dy*dy);
  (dx /= e) *= (2*V);
  (dy /= e) *= (2*V);
  dx -= V;
  // above tangent? (sin(q), cos(q))
  if (sin(q) * dy >= cos(q) * dx) {
    chmin(ans, t + e / (2*V));
    return true;
  } else {
    return false;
  }
}

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%lf%lf%lf", &V, &R, &D);
    
    ans = D / V;
    Double lo = PI/2, hi = PI;
    if (check(hi)) {
      for (int iter = 0; iter < 100; ++iter) {
        const Double mid = (lo + hi) / 2.0;
        (check(mid) ? hi : lo) = mid;
      }
    }
    printf("%.12f\n", ans);
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

Details

answer.code: In function ‘bool check(Double)’:
answer.code:73:15: error: ‘ellint_2’ was not declared in this scope
   73 |   t += 2.0 * (ellint_2(0.5, q + PI/2) - ellint_2(0.5, PI/2));
      |               ^~~~~~~~
answer.code: In function ‘int main()’:
answer.code:94:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   94 |     scanf("%lf%lf%lf", &V, &R, &D);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~