bzoj5020

$$答案误差只要小于 10^{-7}$$

题解

Taylor展开式:

\[若f(x)的n阶导数在[a, b]内连续,则f(x)在x_{0}\in[a, b]可表示为
\]

\[f(x)=\sum_{i=0}^{n} \frac{ f^{(n)}(x_{0})(x-x_{0})^{i} }{i!} + \Theta((x-x_{0})^{n})
\]

\[其中f^{(n)}表示函数f的n阶导数,\Theta((x-x_{0})^{n})为误差
\]

\[对于这道题,令x_{0}=0,求大约12阶导数即可保证误差小于10^{-7}
\]

用Taylor展开式可以直接把路径上的函数合并

直接开12变量个记录每一阶的导数,用LCT维护,统计答案用Taylor展开式计算

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(400010);
const double E = pow(2, 1.0 / log(2)); IL ll Read(){
RG char c = getchar(); RG ll x = 0, z = 1;
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
} int n, m; namespace LCT{
int ch[2][_], fa[_], rev[_], S[_];
double w[17][_], sum[17][_]; IL bool Son(RG int x){ return ch[1][fa[x]] == x; } IL bool Isroot(RG int x){ return ch[0][fa[x]] != x && ch[1][fa[x]] != x; } IL void Update(RG int x){ for(RG int i = 0; i < 16; ++i) sum[i][x] = sum[i][ch[0][x]] + sum[i][ch[1][x]] + w[i][x]; } IL void Pushdown(RG int x){ if(!rev[x]) return; rev[x] ^= 1; rev[ch[0][x]] ^= 1; rev[ch[1][x]] ^= 1; swap(ch[0][x], ch[1][x]); } IL void Rot(RG int x){
RG int y = fa[x], z = fa[y], c = Son(x);
if(!Isroot(y)) ch[Son(y)][z] = x; fa[x] = z;
ch[c][y] = ch[!c][x]; fa[ch[c][y]] = y;
ch[!c][x] = y; fa[y] = x; Update(y);
} IL void Splay(RG int x){
RG int top = 0; S[++top] = x;
for(RG int i = x; !Isroot(i); i = fa[i]) S[++top] = fa[i];
while(top) Pushdown(S[top--]);
for(RG int y = fa[x]; !Isroot(x); Rot(x), y = fa[x])
if(!Isroot(y)) Son(x) ^ Son(y) ? Rot(x) : Rot(y);
Update(x);
} IL void Access(RG int x){ for(RG int y = 0; x; y = x, x = fa[x]) Splay(x), ch[1][x] = y, Update(x); } IL int Findroot(RG int x){ Access(x); Splay(x); while(ch[0][x]) x = ch[0][x]; return x; } IL void Makeroot(RG int x){ Access(x); Splay(x); rev[x] ^= 1; } IL void Split(RG int x, RG int y){ Makeroot(x); Access(y); Splay(y); } IL void Link(RG int x, RG int y){ Makeroot(x); fa[x] = y; } IL void Cut(RG int x, RG int y){ Split(x, y); ch[0][y] = fa[x] = 0; } IL double Query(RG int x, RG int y, RG double xx){
Split(x, y);
RG double ans = sum[0][y], fac = 1, xxx = 1;
for(RG int i = 1; i < 16; i++) fac *= i, xxx *= xx, ans += sum[i][y] / fac * xxx;
return ans;
} IL void Calc(RG int x, RG int f, RG double a, RG double b){
for(RG int i = 0; i < 16; ++i) w[i][x] = 0;
if(f == 3) w[0][x] = b, w[1][x] = a;
else if(f == 1){
RG double aa = 1; w[0][x] = sin(b);
for(RG int i = 1; i < 16; ++i){
aa *= a;
if(i % 4 == 1) w[i][x] = aa * cos(b);
else if(i % 4 == 2) w[i][x] = -aa * sin(b);
else if(i % 4 == 3) w[i][x] = -aa * cos(b);
else w[i][x] = aa * sin(b);
}
}
else{
w[0][x] = pow(E, b);
for(RG int i = 1; i < 16; ++i) w[i][x] = w[i - 1][x] * a;
}
} IL void Work(){
RG char c; RG int u, v, p, f; RG double x, a, b;
for(RG int i = 1; i <= n; ++i) f = Read(), scanf("%lf%lf", &a, &b), Calc(i, f, a, b);
while(m--){
scanf(" %c", &c);
if(c == 'a') u = Read() + 1, v = Read() + 1, Link(u, v);
else if(c == 'd') u = Read() + 1, v = Read() + 1, Cut(u, v);
else if(c == 'm') p = Read() + 1, f = Read(), scanf("%lf%lf", &a, &b), Calc(p, f, a, b), Splay(p);
else{
u = Read() + 1; v = Read() + 1; scanf("%lf", &x);
if(Findroot(u) != Findroot(v)) puts("unreachable");
else printf("%.8e\n", Query(u, v, x));
}
}
}
} int main(RG int argc, RG char *argv[]){
n = Read(); m = Read(); Read();
LCT::Work();
return 0;
}

[THUWC 2017]在美妙的数学王国中畅游的更多相关文章

  1. 【BZOJ5020】[THUWC 2017]在美妙的数学王国中畅游 泰勒展开+LCT

    [BZOJ5020][THUWC 2017]在美妙的数学王国中畅游 Description 数字和数学规律主宰着这个世界. 机器的运转, 生命的消长, 宇宙的进程, 这些神秘而又美妙的过程无不可以用数 ...

  2. BZOJ5020: [THUWC 2017]在美妙的数学王国中畅游(LCT,泰勒展开,二项式定理)

    Description 数字和数学规律主宰着这个世界.   机器的运转,   生命的消长,   宇宙的进程,   这些神秘而又美妙的过程无不可以用数学的语言展现出来.   这印证了一句古老的名言:   ...

  3. bzoj5020: [THUWC 2017]在美妙的数学王国中畅游

    Description 数学王国中,每个人的智商可以用一个属于 [0,1]的实数表示.数学王国中有 n 个城市,编号从 0 到 n−1 ,这些城市由若干座魔法桥连接.每个城市的中心都有一个魔法球,每个 ...

  4. 解题:THUWC 2017 在美妙的数学王国中畅游

    题面 _“数字和数学规律主宰着这个世界.”_ 在 @i207M 帮助下折腾了半天终于搞懂了导数和泰勒展开,引用某学长在考场上的感受:感觉整个人都泰勒展开了 显然是个奇奇怪怪的东西套上LCT,发现直接维 ...

  5. BZOJ5020 [THUWC 2017]在美妙的数学王国中畅游LCT

    题意很明显是要用LCT来维护森林 难点在于如何处理函数之间的关系 我们可以根据题目给的提示关于泰勒展开的式子 将三种函数变成泰勒展开的形式 因为$x∈[0,1]$ 所以我们可以将三个函数在$x_0=0 ...

  6. bzoj 5020(洛谷4546) [THUWC 2017]在美妙的数学王国中畅游——LCT+泰勒展开

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5020 https://www.luogu.org/problemnew/show/P4546 ...

  7. loj2289 [THUWC 2017]在美妙的数学王国中畅游(LCT+Taylor展开)

    link 题目大意: 你需要维护一个树 每个点都有个sin(ax+b)或exp(ax+b)或ax+b 你需要维护一些操作:连边.删边.修改某个点的初等函数.询问某条树链上所有函数带入某个值后权值和或不 ...

  8. bzoj 5020: [THUWC 2017]在美妙的数学王国中畅游【泰勒展开+LCT】

    参考:https://www.cnblogs.com/CQzhangyu/p/7500328.html --其实理解了泰勒展开之后就是水题呢可是我还是用了两天时间来搞懂啊 泰勒展开是到正无穷的,但是因 ...

  9. bzoj5020 & loj2289 [THUWC 2017]在美妙的数学王国中畅游 LCT + 泰勒展开

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=5020 https://loj.ac/problem/2289 题解 这个 appear 和 d ...

随机推荐

  1. SpringBoot入门Demo

    前言:相信做java后台编程的童鞋都知道Spring家族,Spring作为我们项目中必备的框架.JavaSpringBoot号称javaEE的颠覆者,这引起了本Y的好奇,这才花费了一点时间,学习了下s ...

  2. Function与Object的关系

    这里先简单介绍一下我研究这个问题的初衷.起初我只是想研究一下原型链的基本思想.构造函数拥有prototype属性,指向它的prototype,而该构造函数的实例化对象则拥有一个[[prototype] ...

  3. Vue.js响应式原理

      写在前面 因为对Vue.js很感兴趣,而且平时工作的技术栈也是Vue.js,这几个月花了些时间研究学习了一下Vue.js源码,并做了总结与输出. 文章的原地址:answershuto/learnV ...

  4. .addClass(),.removeClass(),.toggleClass()的区别

    .addClass("className")方法是用来给指定元素增加类名,也就是说给指定的元素追加样式: 可以同时添加多个类名,空格符隔开 $("selector&quo ...

  5. Sublime Text编辑远程Linux服务器上的文件

    sublime有个叫sftp的插件,可以通过它直接打开远程机器上的文件进行编辑,并在保存后直接同步到远程linux服务器上. 用Package Control安装插件 按下Ctrl+Shift+P调出 ...

  6. 02 浅析Spring的AOP(面向切面编程)

    1.关于AOP AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善.O ...

  7. 使用Socket对序列化数据进行传输(基于C#)

    客户端代码 [Serializable] // 表示该类可以被序列化 class Person{ public string name; public void HI() { Debug.Log(na ...

  8. the c programing language 学习过程3

    ControlFlow  控制流 specify 指定 compound statement 复合语句 cryptic有隐含意义的 ambiguity歧义 robust稳健 disintegratio ...

  9. Codeforces348C - Subset Sums

    Portal Description 给出长度为\(n(n\leq10^5)\)的序列\(\{a_n\}\)以及\(m(m\leq10^5)\)个下标集合\(\{S_m\}(\sum|S_i|\leq ...

  10. ThreadLoacl,InheritableThreadLocal,原理,以及配合线程池使用的一些坑

    虽然使用AOP可以获取方法签名,但是如果要获取方法中计算得出的数据,那么就得使用ThreadLocal,如果还涉及父线程,那么可以选择InheritableThreadLocal. 注意:理解一些原理 ...