#include <cmath>#include <cstdio>#include <cstdlib>double h[1024];bool calc(int n, double a, double m){ bool ret = true; h[1] = a; h[2] = m; for (int i = 3; i <= n; i++) { h[i] = 2 * (h[i - 1] + 1) - h[i - 2]; if (h[i] < 0.0) { ret = false; } } return ret;}int main(){ int re, n; double a, l, r, m; scanf("%d", &re); while (re--) { scanf("%d%lf", &n, &a); l = 0; r = a; while (r - l > 1e-8) { m = (l + r) / 2.0; if (calc(n, a, m)) { r = m; } else { l = m; } } calc(n, a, (l + r) / 2); printf("%.2lfn", fabs(h[n])); if (re) { putchar('n'); } } return 0;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)