QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#497159#9136. Exponent Calculatorhos_lyricAC ✓0ms4048kbC++142.6kb2024-07-28 20:25:002024-07-28 20:25:04

Judging History

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

  • [2024-07-28 20:25:04]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:4048kb
  • [2024-07-28 20:25:00]
  • 提交

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 <random>
#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")


/*
  y = x/2^E
  z = 1/N!
  z <- 1/(N-1)! + y z
  ...
  z <- 1/1! + y z
  z <- 1/0! + y z
  z <- z^(2^E)
  
  1 + (2N+1) + E
*/

constexpr int K = 25;
constexpr int L = 20;

void check(int E, int N) {
  vector<double> invFac(N + 1);
  invFac[0] = 1.0;
  for (int i = 1; i <= N; ++i) invFac[i] = invFac[i - 1] / i;
  vector<double> errors(2*L+1);
  double maxError = 0.0;
  for (int x = -L; x <= +L; ++x) {
    double y = (double)x / (1<<E);
    double z = invFac[N];
    for (int i = N; --i >= 0; ) z = invFac[i] + y * z;
    for (int e = 0; e < E; ++e) z = z * z;
    const double error = (z - exp(x)) / exp(x);
    errors[L + x] = error;
    chmax(maxError, abs(error));
  }
  cerr << E << " " << N << ": " << maxError << endl;
  cerr << errors << endl;
  cerr << endl;
  
  const char *X = "$1";
  const char *Y = "$2";
  const char *Z = "$0";
  printf("%d\n", 1 + (2*N+1) + E);
  printf("%s = %s * %.100f\n", Y, X, 1.0 / (1<<E));
  printf("%s = %.100f\n", Z, invFac[N]);
  for (int i = N; --i >= 0; ) {
    printf("%s = %s * %s\n", Z, Y, Z);
    printf("%s = %.100f + %s\n", Z, invFac[i], Z);
  }
  for (int e = 0; e < E; ++e) {
    printf("%s = %s * %s\n", Z, Z, Z);
  }
}

int main() {
  /*
  for (int E = 0; E <= K - 2; ++E) {
    const int N = (K - 2 - E) / 2;
    check(E, N);
  }
  */
  check(9, 7);
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 4048kb

input:

input

output:

25
$2 = $1 * 0.0019531250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
$0 = 0.0001984126984126984125263171154784913596813566982746124267578125000000000000000000000000000000000000
$0 = $2 * $0
$0 = 0.00138888888888888894189432843262466121814213693141937255...

result:

ok max relative diff is 1.62383e-13. Checker runtime is 208 ms

Extra Test:

score: 0
Extra Test Passed