计算积分
保留至小数点后5位。若积分发散,请输出"orz"。
输入格式:
一行,包含一个实数,为a的值
输出格式:
一行,积分值或orz
输入样例#1: 复制
2.33
输出样例#1: 复制
1.51068
a<=50
请注意时空限制。
观察到函数具有极强的收敛性
然后估算一下上界,直接上辛普森积分
// luogu-judger-enable-o2
#include<cstdio>
#include<cmath>
double a;
double F(double x) {
return pow(x, a / x - x);
}
double sim(double l, double r) {
return (F(l) + F(r) + 4 * F((l + r) / 2)) * (r - l) / 6;
}
double asr(double L, double R, double eps, double ans) {
double mid = (L + R) / 2;
double LL = sim(L, mid), RR = sim(mid, R);
if(fabs(LL + RR - ans) <= 15 * eps) return LL + RR;
return asr(L, mid, eps / 2, sim(L, mid)) + asr(mid, R, eps / 2, sim(mid, R));
}
main() {
#ifdef WIN32
freopen("a.in", "r", stdin);
#endif
scanf("%lf", &a);
if(a < 0) {printf("orz");return 0;}
printf("%.5lf", asr(1e-9, 20, 1e-7, sim(0, 20)));
}