zoj 2056 Garland

zoj 2056 Garland,第1张

zoj 2056 Garland
#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;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4935337.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-13
下一篇 2022-11-13

发表评论

登录后才能评论

评论列表(0条)

保存