結果

問題 No.456 Millions of Submits!
ユーザー はむ吉🐹はむ吉🐹
提出日時 2017-02-04 14:27:38
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 2,160 ms / 4,500 ms
コード長 878 bytes
コンパイル時間 1,991 ms
コンパイル使用メモリ 150,928 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 01:19:42
合計ジャッジ時間 11,994 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 24 ms
4,380 KB
testcase_10 AC 24 ms
4,380 KB
testcase_11 AC 219 ms
4,376 KB
testcase_12 AC 2,160 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(27): Deprecation: template `std.math.operations.approxEqual(T, U, V)(T value, U reference, V maxRelDiff = 0.01, V maxAbsDiff = 1e-05)` is deprecated - approxEqual will be removed in 2.106.0. Please use isClose instead.
Main.d(41):        instantiated from here: `solveEquation!real`
Main.d(29): Deprecation: template `std.math.operations.approxEqual(T, U, V)(T value, U reference, V maxRelDiff = 0.01, V maxAbsDiff = 1e-05)` is deprecated - approxEqual will be removed in 2.106.0. Please use isClose instead.
Main.d(41):        instantiated from here: `solveEquation!real`
Main.d(17): Deprecation: template `std.math.operations.approxEqual(T, U, V)(T value, U reference, V maxRelDiff = 0.01, V maxAbsDiff = 1e-05)` is deprecated - approxEqual will be removed in 2.106.0. Please use isClose instead.
Main.d(32):        instantiated from here: `lambertW!real`
Main.d(41):        instantiated from here: `solveEquation!real`

ソースコード

diff #

import std.algorithm.iteration;
import std.conv;
import std.math;
import std.stdio;
import std.string;


const real EPS = 1e-10;


// https://ja.wikipedia.org/wiki/ランベルトのW関数
T lambertW(T)(T z, T tol=EPS, int iter=1000){
	T xi = 1.0f;
	T xj;
	foreach (i; 0 .. iter){
		xj = xi - (xi * exp(xi) - z) / (exp(xi) + xi * exp(xi));
		if (approxEqual(xi, xj, EPS)){
			return xj;
		}
		xi = xj;
	}
	throw new Exception("Failure: No convergence");
}


T solveEquation(T)(T a, T b, T t, T tol=EPS){
	if (approxEqual(a, 0, EPS)){
		return exp(pow(t, 1 / b));
	} else if (approxEqual(b, 0, EPS)) {
		return pow(t, 1 / a);
	} else {
		return exp(b / a * lambertW(a / b * pow(t, 1 / b)));
	}
}


void main(){
	auto m = readln.chomp.to!int;
	foreach (i; 0..m) {
		auto s = readln.split.map!(to!real);
		auto res = solveEquation(s[0], s[1], s[2]);
		writefln("%.11f", res);
	}
}
0