题意:,求这个函数在[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. 腾讯云集群服务部署mysql并挂载到服务器

    一.背景 由于现在大部分的应用都是运行在云服务器上的,而现在大多数文章都是主要写如何在服务器上使用docker去运行mysql,比较少有介绍云服务器上的.再加上现在k8s比较火爆,而云厂商大多数都提供 ...

  2. PHP出现SSL certificate:unable to get local issuer certificate的解决办法

    当本地curl需要访问https时,如果没有配置证书,会出现SSL certificate: unable to get local issuer certificate错误信息. 解决办法: 1.下 ...

  3. php+mysql数据库联合查询 left join 右侧数据重复问题

    情况:多表联合查询(三表及以上联合查询) 分析: A left join B left join C left join D 假如: 表B.C.D都与表A关联查询 A left join B 4条数据 ...

  4. Apache solr velocity模块 漏洞复现

    0x01 Solr简单介绍 Solr是建立在Apache Lucene ™之上的一个流行.快速.开放源代码的企业搜索平台. Solr具有高度的可靠性,可伸缩性和容错能力,可提供分布式索引,复制和负载平 ...

  5. shiro:入门程序(一)

    SpringMVC项目 1:pom引入相关依赖 <dependencies> <!--测试依赖--> <dependency> <groupId>jun ...

  6. 基于Neo4j的个性化Pagerank算法文章推荐系统实践

    新版的Neo4j图形算法库(algo)中增加了个性化Pagerank的支持,我一直想找个有意思的应用来验证一下此算法效果.最近我看Peter Lofgren的一篇论文<高效个性化Pagerank ...

  7. tensorflow1.0 模型的保存与加载

    import tensorflow as tf import numpy as np # ##Save to file # W = tf.Variable([[4,5,6],[7,8,9]],dtyp ...

  8. python-trade

    https://tool.lu/pyc/在线反编译pyc import base64 correct = 'XlNkVmtUI1MgXWBZXCFeKY+AaXNt' flag = base64.b6 ...

  9. RabbitMQ Hello world(二)

    简介: Rabbitmq 是消息代理中间件,它接收或者发送消息.你可以把它想想宬一个邮局:当你把邮件放到邮箱时,你可以确定某一位邮递员可以准确的把邮件送到收件人手中,在这个比喻中,rabbitmq是一 ...

  10. 【ubuntu】windows+ubuntu 设置windows为第一启动项

    进入ubuntu系统 sudo su vim /etc/default/grub 更改GRUB_DEFAULT=后的值默认是0,如果你的windows启动项在第5个就改成4.改完之后退出保存输入 up ...