栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2518 Wrapping Pillar

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2518 Wrapping Pillar

#include <cmath>#include <iomanip>#include <iostream>#include <algorithm>using namespace std;template<class Tp, class Fo>Tp RombergIntegral(Tp lowerBound, Tp upperBound, Fo f, Tp eps, int MAXK = 16){    Tp h = upperBound - lowerBound;    Tp *T = new double[MAXK];    int K = 1;    T[0] = (f(lowerBound) + f(upperBound)) * h / 2.0;    double cmp = T[0];    while(true){        Tp tmp = 0;        for(Tp x = lowerBound + h/2.0; x < upperBound; x += h) tmp += f(x);        tmp = (T[0] + tmp * h) / 2.0;        Tp power4 = 1.0;        for(int i = 0; i < K; i++){ power4 *= 4.0; Tp cur = tmp + (tmp - T[i]) / (power4 - 1.0); T[i] = tmp; tmp =cur;        }        T[K] = tmp;        if(K>=4 && fabs(tmp - cmp) < eps) break;        cmp = T[K];        h /= 2.0;        K++;    }    return T[K];}template<class T>class EllipseFunction{    private:        T _a;        T _c;    public:        EllipseFunction(T a = 0.0, T c = 0.0) : _a(a), _c(c) { }        inline T operator()(T x){ T cur = sin(x) * _c / _a; return sqrt(1 - cur * cur);        }};int main(){    const double PI = acos(-1.0);    const double lowerBound = 0.0, upperBound = PI / 2.0;    double h, a, b;    while(cin >> h >> a >> b) {        if(a < b) swap(a, b);        EllipseFunction<double> fuction(a, sqrt(a * a - b * b));        double perimeter = 4.0 * a * RombergIntegral<double,EllipseFunction<double> >(lowerBound, upperBound, fuction, 1e-10);        cout << setiosflags(ios::fixed) << setprecision(2) << h * perimeter << endl;    }}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379142.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号