数值积分 (辛普森公式 辛普森自适应法则) UVA
2013-04-23 20:41
381 查看
double F(double x) { } double simpson(double l, double r) { double m = (l + r) * 0.5; return (F(l) + 4 * F(m) + F(r)) * (r - l) / 6.0; } double asr(double l, double r, double eps, double A) { double m = (l + r) * 0.5; double L = simpson(l, m), R = simpson(m, r); if (fabs(L + R - A) <= 15 * eps) return L + R + (L + R - A) / 15.0; return asr(l, m, eps * 0.5, L) + asr(m, r, eps * 0.5, R); } double asr(double l, double r, double eps) { return 2.0 * asr(l, r, eps, simpson(l, r)); } int dblcmp(double x) { if (x < -eps) return -1; return x > eps; }
UVA 1356
#include<cstdio> #include<cstring> #include<queue> #include<vector> #include<iostream> #include<string> #include<sstream> #include<cctype> #include<set> #include<stack> #include<numeric> #include<functional> #include<memory> #include<deque> #include<list> #include<cmath> #include<fstream> #include<cstdlib> #include<climits> #include<iomanip> #include<cstring> #include<memory> #include<bitset> #include<algorithm> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; const double eps = 1e-10; const int maxn = 1111; const int mod = 1000000007; const int N = 1111; const int M = 111111; const int INF = 0x7f7f7f7f; double a, w, h; double F(double x) { return sqrt(1 + 4.0 * a * a * x * x); } double simpson(double l, double r) { double m = (l + r) * 0.5; return (F(l) + 4 * F(m) + F(r)) * (r - l) / 6.0; } double asr(double l, double r, double eps, double A) { double m = (l + r) * 0.5; double L = simpson(l, m), R = simpson(m, r); if (fabs(L + R - A) <= 15 * eps) return L + R + (L + R - A) / 15.0; return asr(l, m, eps * 0.5, L) + asr(m, r, eps * 0.5, R); } double asr(double l, double r, double eps) { return 2.0 * asr(l, r, eps, simpson(l, r)); } int dblcmp(double x) { if (x < -eps) return -1; return x > eps; } int main() { double D, H, B, L; int cas; int n, T; double L1; scanf("%d", &T); for (cas = 1; cas <= T; ++cas) { scanf("%lf%lf%lf%lf", &D, &H, &B, &L); if (cas > 1) puts(""); n = (int) ceil(B * 1.0 / D); D = B * 1.0 / n; L1 = L * 1.0 / n; double len, l, r, m; l = 0, r = H; w = D; while (r - l > eps) { m = (l + r) * 0.5; h = m; a = 4.0 * h / (w * w); len = asr(0, w * 0.5, 1e-6); if (dblcmp(len - L1) < 0) l = m; else r = m; } printf("Case %d:\n%.2lf\n", cas, 0.0 + H - h); } return 0; }
相关文章推荐
- 数值积分_自适应辛普森法
- 数值积分-自适应辛普森法
- UVALive-3485 Bridge(二分答案+自适应辛普森积分)
- UVALive - 3485 Bridge 二分+数学+自适应辛普森求积分
- 自适应辛普森公式求积分模板
- 自适应辛普森(近似求积分)
- 数值积分之Simpson 3/8法则
- HDU 1724 Ellipse(数值积分の辛普森公式)
- UVA 1356 - Bridge(自适应辛普森)
- BZOJ 1502 NOI 2005 月下柠檬树 计算几何 自适应辛普森积分
- [LOJ2267][SDOI2017]龙与地下城-FFT-自适应辛普森积分
- 变步长辛普森求数值积分
- 数值积分之Simpson 1/3法则
- UVA 1356 - Bridge(自适应辛普森)
- 自适应辛普森积分
- uva 1356 Bridge ( 辛普森积分 )
- UVA 1356 - Bridge(自适应辛普森)
- 自适应辛普森公式求积分
- BZOJ 1502 月下柠檬树 自适应辛普森积分
- HDU 1724 Ellipse (自适应辛普森积分模板题)