[THUWC2017][bzoj5020] 在美妙的数学王国中畅游 [LCT+泰勒展开]
题面
思路

这里很重要
它提示我们,把给定的三个函数泰勒展开,并用LCT维护每一项泰勒展开式的值,维护十几项就满足了题目的精度要求
我们考虑一个函数在0位置的泰勒展开
$f(x)=\sum_{i=0}^{\infty} \frac{x^i f^{(i)}(0)}{i!}$
发现后面式子里面的$\frac{xi}{x!}$可以留到询问时候处理,我们只需要维护$\sum_{i=0}{\infty} f^{(i)}(0)$即可
对于$f(x)=sin(ax+b)$,其导函数如下:
$f{(4n)}(x)=a{4n}sin(ax+b)$
$f{(4n+1)}(x)=a{4n+1}cos(ax+b)$
$f{(4n+2)}(x)=-a{4n+2}sin(ax+b)$
$f{(4n+3)}(x)=-a{4n+3}cos(ax+b)$
对于$f(x)=e^{ax+b}$,其导函数如下:
$f{(n)}(x)=a{n}e^{ax+b}$(其实就是乘了一个$a$的幂)
对于$f(x)=ax+b$,其一阶导数为$f'(x)=a$,没有更高阶导数
所以,我们在$x=0$的位置泰勒展开这三个函数,并且LCT维护、询问即可
详见代码
Code
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<cmath>
#define ll long double
using namespace std;
inline int read(){
int re=0,flag=1;char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') flag=-1;
ch=getchar();
}
while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
return re*flag;
}
int fa[200010],ch[200010][2],rev[200010];
long double w[200010][15],sum[200010][15],a[200010],b[200010];int tp[200010];
//tp={1,2,3} --> {sin,exp,ax+b}
void calc(int cur){//这里是计算泰勒展开值
//注意因为我们取的位置是x=0,所以展开以后保存的函数自变量取值为0a+b=b
ll A=a[cur],B=b[cur],*val=w[cur];register int i;
switch(tp[cur]){
case 3://sin(ax+b)
val[0]=B;val[1]=A;
for(i=2;i<12;i++) val[i]=0;
break;
case 2://exp(ax+b)
val[0]=exp(B);
for(i=1;i<12;i++) val[i]=val[i-1]*A;
break;
case 1://ax+b
val[0]=sin(B);
val[1]=A*cos(B);
for(i=2;i<12;i++) val[i]=-val[i-2]*A*A;
break;
default:assert(0);
}
}
void update(int cur){
for(register int i=0;i<12;i++) sum[cur][i]=sum[ch[cur][0]][i]+sum[ch[cur][1]][i]+w[cur][i];
}
void pushrev(int cur){
if(!cur) return;
swap(ch[cur][0],ch[cur][1]);
rev[cur]^=1;
}
void pushdown(int cur){
if(!rev[cur]) return;
pushrev(ch[cur][0]);
pushrev(ch[cur][1]);
rev[cur]=0;
}
bool nroot(int cur){return ch[fa[cur]][0]==cur||ch[fa[cur]][1]==cur;}
void push(int cur){
if(nroot(cur)) push(fa[cur]);
pushdown(cur);
}
bool get(int cur){return ch[fa[cur]][1]==cur;}
void rotate(int x){
int f=fa[x],ff=fa[f],son=get(x),nr=nroot(f);
ch[f][son]=ch[x][son^1];
if(ch[f][son]) fa[ch[f][son]]=f;
fa[f]=x;ch[x][son^1]=f;
fa[x]=ff;
if(nr) ch[ff][ch[ff][1]==f]=x;
update(f);update(x);
}
void splay(int x){
push(x);
for(int f;nroot(x);rotate(x)){
f=fa[x];
if(nroot(f)){
rotate((get(x)==get(f))?f:x);
}
}
}
void access(int x){
for(int y=0;x;y=x,x=fa[x]){
splay(x);ch[x][1]=y;update(x);
}
}
void mroot(int u){
access(u);splay(u);pushrev(u);
}
void link(int u,int v){
mroot(u);fa[u]=v;
}
void cut(int u,int v){
mroot(u);access(v);splay(v);
fa[u]=ch[v][0]=0;update(v);
}
int find(int u){
access(u);splay(u);
while(ch[u][0]) u=ch[u][0];
return u;
}
long double query(int u,int v,long double x){
mroot(u);access(v);splay(v);
long double re=0,tmp=1;register int i;
for(i=0;i<12;i++){
re+=tmp*(long double)(sum[v][i]);
tmp/=(long double)(i+1);tmp*=x;
}
return re;
}
int n,m;char s[20];
int main(){
n=read();m=read();scanf("%s",s);int i,t1,t2;double t3,t4;
for(i=1;i<=n;i++){
fa[i]=ch[i][0]=ch[i][1]=rev[i]=0;
tp[i]=read();
scanf("%lf%lf",&t3,&t4);
a[i]=t3;b[i]=t4;
calc(i);
}
while(m--){//注意题目中点是从0开始的
scanf("%s",s);
if(s[0]=='a'){
t1=read();t2=read();
t1++;t2++;
link(t1,t2);
}
if(s[0]=='d'){
t1=read();t2=read();
t1++;t2++;
cut(t1,t2);
}
if(s[0]=='m'){
t1=read();t1++;
tp[t1]=read();
scanf("%lf%lf",&t3,&t4);
a[t1]=t3;b[t1]=t4;
mroot(t1);calc(t1);update(t1);
}
if(s[0]=='t'){
t1=read();t2=read();scanf("%lf",&t3);
t1++;t2++;
if(find(t1)!=find(t2)) puts("unreachable");
else printf("%.10lf\n",(double)(query(t1,t2,t3)));
}
}
}
[THUWC2017][bzoj5020] 在美妙的数学王国中畅游 [LCT+泰勒展开]的更多相关文章
- 【BZOJ5020】[LOJ2289]【THUWC2017】在美妙的数学王国中畅游 - LCT+泰勒展开
咕咕咕?咕咕咕! 题意: Description 数字和数学规律主宰着这个世界. 机器的运转, 生命的消长, 宇宙的进程, 这些神秘而又美妙的过程无不可以用数学的语言展现出来. 这印证了一句古老的名言 ...
- 【BZOJ5020】【THUWC2017】在美妙的数学王国中畅游 LCT 泰勒展开
题目大意 给你一棵树,每个点有一个函数\(f(x)\) 正弦函数 \(\sin(ax+b) (a\in[0,1],b\in[0,\pi],a+b\in[0,\pi])\) 指数函数 \(e^{ax+b ...
- BZOJ5020: [THUWC 2017]在美妙的数学王国中畅游(LCT,泰勒展开,二项式定理)
Description 数字和数学规律主宰着这个世界. 机器的运转, 生命的消长, 宇宙的进程, 这些神秘而又美妙的过程无不可以用数学的语言展现出来. 这印证了一句古老的名言: ...
- [THUWC2017]在美妙的数学王国中畅游 LCT+泰勒展开+求导
p.s. 复合函数求导时千万不能先带值,再求导. 一定要先将符合函数按照求导的规则展开,再带值. 设 $f(x)=g(h(x))$,则对 $f(x)$ 求导: $f'(x)=h'(x)g'(h(x)) ...
- bzoj5020 & loj2289 [THUWC 2017]在美妙的数学王国中畅游 LCT + 泰勒展开
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=5020 https://loj.ac/problem/2289 题解 这个 appear 和 d ...
- 「LOJ 2289」「THUWC 2017」在美妙的数学王国中畅游——LCT&泰勒展开
题目大意: 传送门 给一个动态树,每个节点上维护一个函数为$f(x)=sin(ax+b)$.$f(x)=e^{ax+b}$.$f(x)=ax+b$中的一个. 支持删边连边,修改节点上函数的操作. 每次 ...
- bzoj 5020(洛谷4546) [THUWC 2017]在美妙的数学王国中畅游——LCT+泰勒展开
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5020 https://www.luogu.org/problemnew/show/P4546 ...
- 洛谷 P4546 & bzoj 5020 在美妙的数学王国中畅游 —— LCT+泰勒展开
题目:https://www.luogu.org/problemnew/show/P4546 先写了个55分的部分分,直接用LCT维护即可,在洛谷上拿了60分: 注意各处 pushup,而且 spla ...
- 【BZOJ5020】【THUWC2017】在美妙的数学王国中畅游(Link-Cut Tree,组合数学)
[BZOJ5020][THUWC2017]在美妙的数学王国中畅游(Link-Cut Tree,组合数学) 题解 Description 数字和数学规律主宰着这个世界. 机器的运转, 生命的消长, 宇宙 ...
随机推荐
- chisel(安装)
github地址 先安装homeBrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/m ...
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [spring/applicationContext-service.xml]: Cannot resolve refer
<!-- aop --> <aop:config> <aop:pointcut expression="execution(* com.zsn.Service. ...
- Springcloud Eureka 启动失败:ERROR org.springframework.boot.SpringApplication - Application run failed
在测试Euruka作为服务注册中心的时候碰到了这个问题 [main] ERROR org.springframework.boot.SpringApplication - Application ru ...
- thymeleaf单选回显,多选回显,选回显,下拉默认选中第一个
//默认选中第一个<input type ="radio" name="repaymentType" th:each ="repaymentTy ...
- CSS选取指定位置标签first-child、last-child、nth-child
1.first-child 选择列表中的第一个标签. 2.last-child 选择列表中的最后一个标签 3.nth-child(n) 选择列表中的第n个标签 4.nth-child(2n) 选择列表 ...
- Redis在windows下安装过程(转)
(转)原文:http://www.cnblogs.com/M-LittleBird/p/5902850.html 要使redis在PHP下运行, 需在PHP文件下的ext扩展文件夹中添加扩展文件 ph ...
- C语言函数篇(一)函数的组成
函数的组成: 函数名 输入参数 返回值 返回值 函数名 (输入参数){ 执行体 } 用指针保存函数: int func(int a, int b, char c){ } --> int (*fu ...
- C# 在窗口绘制图形(打点、画圆、画线)
需要包含命名空间 using System.Drawing; 画图前需要先创建画板 void Display() { Graphics g = this.CreateGraphics(); //创建画 ...
- 笔记-爬虫-selenium常用方法
笔记-爬虫-selenium常用方法 1. 查找元素 常用的查找方法 find_element_by_name find_element_by_xpath find_element_by_l ...
- oracle11g导出表时空表导不出解决方案
oracle11g用exp命令导出数据库表时,有时会发现只导出了一部分表时而且不会报错,原因是有空表没有进行导出,之前一直没有找到方法于是用最笨的方法重新建这些空表,当然在我们实际当中表的数量大时我们 ...