結果
| 問題 |
No.456 Millions of Submits!
|
| コンテスト | |
| ユーザー |
はむこ
|
| 提出日時 | 2016-12-09 02:22:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 219 ms / 4,500 ms |
| コード長 | 2,451 bytes |
| コンパイル時間 | 2,167 ms |
| コンパイル使用メモリ | 159,616 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-23 16:47:23 |
| 合計ジャッジ時間 | 9,116 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 17;
const double lte = -4 * log(10);
double lg[N + 2];
double ex[20202];
double fastexp(double x) {
return exp(x);
//int a = floor(x * 1e3);
//double b = x - a * 1e-3;
//return ex[a + 10000] * (((b / 3 + 1) * b / 2 + 1) * b + 1);
}
// ref: https://en.wikipedia.org/wiki/Lambert_W_function, Numerical evaluation
// Halley's method
double lambert(double z, double init) {
double w = init;
for (int i = 0; i < 3; i++) {
double ew = fastexp(w);
double a = w * ew - z;
double b = ew * (w + 1) - (w + 2) * (w * ew - z) / (2 * w + 2);
w -= a / b;
}
return w;
}
namespace fastio {
#define getchar getchar_unlocked
#define putchar putchar_unlocked
bool dot;
int readInt() {
int n, c;
while ((c = getchar()) < '0') {
assert(c != EOF);
}
n = c - '0';
while ((c = getchar()) >= '0') {
n = n * 10 + c - '0';
}
dot = c == '.';
return n;
}
void printDouble(double x) {
int a = x;
int b = (x - a) * 1e9;
int d[15];
int i = 0;
for (int j = 0; j < 9; j++) {
d[i++] = b % 10 + '0';
b /= 10;
}
d[i++] = '.';
do {
d[i++] = a % 10 + '0';
a /= 10;
} while (a > 0);
while (i > 0) {
putchar(d[--i]);
}
putchar('\n');
}
}
double solve(int a, int b, int c, int d) {
double lt = lg[c * 10000 + d];
if (b == 0) {
return fastexp(lt / a);
}
if (a == 0) {
return fastexp(fastexp(lt / b));
}
double init = max(0.0, lt / b + lg[a] - lg[b]);
return fastexp(lambert(fastexp(lt / b) * a / b, init) * b / a);
}
int main() {
for (int i = 0; i <= 20000; i++) {
ex[i] = exp((i - 10000) * 1e-3);
}
for (int i = 0; i < N / 2; i++) {
lg[i] = log(i) + lte;
}
for (int i = N / 2; i < N + 2; i += 2) {
double li = log(i);
double lj = li + 1.0 / i;
lg[i + 0] = li + lte;
lg[i + 1] = lj + lte;
}
int m = fastio::readInt();
for (int i = 0; i < m; i++) {
int a = fastio::readInt();
int b = fastio::readInt();
int c = fastio::readInt();
int d = fastio::dot ? fastio::readInt() : 0;
fastio::printDouble(solve(a, b, c, d));
}
}
はむこ