题意:,求这个函数在[0,100]上的图像的长度。

思路:采用离散化的思想,求出所有交点 ,把交点排序,把[0,100]分成若干个小区间,这样原函数在每个小区间上的图像属于某一个二次函数或者是一条直线。如何确定属于哪个呢?比如对于某个区间,令m为这个小区间的中点,求出所有的函数在m点的函数值的最小值,对应的那个函数就是答案。如果最小值>=100则说明是直线。那么问题就变成了求二次函数曲线在区间[L,R]上的长度。这个可以转化为积分来算,令f(x)为原函数的倒数,则答案就是sqrt(1+f(x)*f(x))在[L,R]上的积分了。求积分可以用自适应辛普森法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 123;
#define _x2(a) (a) * (a)
 
namespace Integral {
    double (*func)(double);
    double simpson(double a, double b) {
        double c = a + (b - a) / 2;
        return (func(a) + func(c) * 4 + func(b)) * (b - a) / 6;
    }
    double asr(double a, double b, double eps, double A) {
        double c = a + (b - a) / 2;
        double L = simpson(a, c), R = simpson(c, b);
        if (fabs(L + R - A) < 15 * eps) return L + R + (L + R - A) / 15;
        return asr(a, c, eps / 2, L) + asr(c, b, eps / 2, R);
    }
    double getans(double a, double b, double eps, double (*f)(double)) {
        func = f;
        return asr(a, b, eps, simpson(a, b));
    }
};
 
int k[maxn], a[maxn], b[maxn];
int A[maxn], B[maxn], C[maxn];
int ga, gb, gc, cnt;
double pos[12345];
 
double F(double x) {
    return ga * x * x + gb * x + gc;
}
double f(double x) {
    return sqrt(1.0 + _x2(2.0 * ga * x + gb));
}
void add(double x) {
    if (x > 0 && x < 100) pos[cnt ++] = x;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt""r", stdin);
#endif // ONLINE_JUDGE
    int T, n;
    cin >> T;
    while (T --) {
        cnt = 0;
        pos[cnt ++] = 0;
        pos[cnt ++] = 100;
        cin >> n;
        for (int i = 0; i < n; i ++) {
            cin >> k[i] >> a[i] >> b[i];
            A[i] = k[i];
            B[i] = -2 * k[i] * a[i];
            C[i] = k[i] * a[i] * a[i] + b[i];
            if (b[i] < 100) {
                double buf = sqrt((100.0 - b[i]) / k[i]);
                add(a[i] + buf);
                add(a[i] - buf);
            }
        }
        for (int i = 0; i < n; i ++) {
            for (int j = i + 1; j < n; j ++) {
                ga = A[i] - A[j];
                gb = B[i] - B[j];
                gc = C[i] - C[j];
                if (ga == 0) {
                    if (gb != 0) add(-1.0 * gc / gb);
                    continue;
                }
                int d = gb * gb - 4 * ga * gc;
                if (d >= 0) {
                    add((-gb - sqrt(1.0 * d)) / 2.0 / ga);
                    if (d) add((-gb + sqrt(1.0 * d)) / 2.0 / ga);
                }
            }
        }
        sort(pos, pos + cnt);
        double ans = 0;
        for (int i = 1; i < cnt; i ++) {
            double L = pos[i - 1], R = pos[i];
            if (R - L < 1e-10) continue;
            double M = (L + R) / 2, minval = 100;
            int target = -1;
            for (int i = 0; i < n; i ++) {
                ga = A[i];
                gb = B[i];
                gc = C[i];
                if (F(M) < minval) {
                    minval = F(M);
                    target = i;
                }
            }
            if (~target) {
                ga = A[target];
                gb = B[target];
                gc = C[target];
                ans += Integral::getans(L, R, 1e-8, f);
            }
            else ans += R - L;
        }
        printf("%.2f\n", ans);
    }
    return 0;
}

[hdu4498]离散化,simpson求积分的更多相关文章

  1. bzoj1502 simpson求面积

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1502 题解: simpson积分求面积,s = (f(a)+f(b)+4*f(c))/6*Δx ...

  2. codeforces_459D_(线段树,离散化,求逆序数)

    链接:http://codeforces.com/problemset/problem/459/D D. Pashmak and Parmida's problem time limit per te ...

  3. Picture POJ - 1177 线段树+离散化+扫描线 求交叉图像周长

    参考  https://www.cnblogs.com/null00/archive/2012/04/22/2464876.html #include <stdio.h> #include ...

  4. HDOJ-6665(离散化+DFS求连通分量)

    Calabash and Landlord HDOJ-6665 这里考察的是离散化的知识. 首先将所有的x坐标和y坐标放入两个数组中,然后对这两个数组进行排序.因为总共的坐标数就5个所以这两个数组的大 ...

  5. 【BZOJ-1502】月下柠檬树 计算几何 + 自适应Simpson积分

    1502: [NOI2005]月下柠檬树 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1017  Solved: 562[Submit][Status] ...

  6. [BZOJ 2178] 圆的面积并 【Simpson积分】

    题目链接:BZOJ - 2178 题目分析 用Simpson积分,将圆按照 x 坐标分成连续的一些段,分别用 Simpson 求. 注意:1)Eps要设成 1e-13  2)要去掉被其他圆包含的圆. ...

  7. 自适应Simpson积分

    自适应Simpson积分 作用 如标题所示,这玩意就是当你不会微积分的时候来求积分的. 总所周知,积分的定义就是函数的某一段与坐标轴之间的面积. 那么,自适应Simpson积分就是一种可以再某些精度下 ...

  8. BZOJ.4909.[SDOI2017]龙与地下城(正态分布 中心极限定理 FFT Simpson积分)

    BZOJ 洛谷 https://www.luogu.org/blog/ShadowassIIXVIIIIV/solution-p3779# 正态分布 正态分布是随机变量\(X\)的一种概率分布形式.它 ...

  9. POJ 2528 区间染色,求染色数目,离散化

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 47905   Accepted: 13903 ...

随机推荐

  1. SpringCloud-Ribbon负载均衡机制、手写轮询算法

    Ribbon 内置的负载均衡规则 在 com.netflix.loadbalancer 包下有一个接口 IRule,它可以根据特定的算法从服务列表中选取一个要访问的服务,默认使用的是「轮询机制」 Ro ...

  2. Trie树-提高海量数据的模糊查询性能

    今天这篇文章源于上周在工作中解决的一个实际问题,它是个比较普遍的问题,无论做什么开发,估计都有遇到过.具体是这样的,我们有一份高校的名单(2657个),需要从海量的文章标题中找到包含这些高校的标题,其 ...

  3. java Int类型转为double 类型;string转double

    int a=12; double b=(double)a; or double c=Double.valueOf((double)a); string a_s="12"; doub ...

  4. Flutter 开发填坑指南

    引言 第一次在使用Flutter是在Ubuntu机器上,但是因为Android Studio还有Sdk配置问题,flutter doctor总是在这一步报错...最近又在win10上配了一下环境(真香 ...

  5. JS流程图解决方案GoJS

    GoJs简介 一个实现交互类图表(比如流程图,树图,关系图,力导图等等)的JS库 GoJS依赖于HTML5,所以请保证您的浏览器版本支持HTML5,当然还要加载这个库. 首先个人建议先下载官方实例的 ...

  6. 2019-2020-1 20199329 第二周测试(环境:ubuntu64位)

    2019-2020-1 20199329 第二周测试(环境:ubuntu64位) 实验一 0.每个.c一个文件,每个.h一个文件,文件名中最好有自己的学号 1.用Vi输入图中代码,并用gcc编译通过 ...

  7. java中functional interface的分类和使用

    目录 简介 Functional Interface Function:一个参数一个返回值 BiFunction:接收两个参数,一个返回值 Supplier:无参的Function Consumer: ...

  8. Spring5参考指南:Environment

    文章目录 Profiles PropertySource 使用@PropertySource Spring的Environment接口有两个关键的作用:1. Profile, 2.properties ...

  9. CentOS7编译安装NodeJS

    概述 在CentOS7下采用编译NodeJS二进制源码包的方式安装NodeJS 下载NodeJS安装包 你可以先下载NodeJS二进制源码安装包文件然后上传到CentOS系统,也可以通过wget命令直 ...

  10. 谷歌浏览器报错Unchecked runtime.lastError: The message port closed before a response was received.。

    浏览器版本 : 报错原因:扩展程序问题 解决建议:打开chrome://extensions/,逐一关闭排查