BZOJ5020: [THUWC 2017]在美妙的数学王国中畅游(LCT,泰勒展开,二项式定理)
Description
Input
Output
Sample Input
1 1 0
3 0.5 0.5
3 -0.5 0.7
appear 0 1
travel 0 1 0.3
appear 0 2
travel 1 2 0.5
disappear 0 1
appear 1 2
travel 1 2 0.5
Sample Output
1.67942554e+000
1.20000000e+000
解题思路:
题目描述如此毒瘤。
从操作3得到的启发,将多项式展开对应项相加。
这道题可以将sin(ax+b),eax+b泰勒展开。
精度的话16位肯定够。剩下的就是裸的LCT了。
听霉霉的歌写泰勒展开不容易错
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#define lll tr[spc].ch[0]
#define rrr tr[spc].ch[1]
#define ls ch[0]
#define rs ch[1]
const int N=;
const int oo=;
struct trnt{
int ch[];
int fa;
int lzt;
int type;
bool anc;
double a,b;
double C[oo];
double f[oo];
double val(double x)
{
double ans=f[];
double t=x;
for(int i=;i<oo;i++,t*=x)
ans+=f[i]*t;
return ans;
}
void Insert(void)
{
scanf("%d",&type);
scanf("%lf%lf",&a,&b);
return ;
}
void Taylor(double *fac)
{
double at[oo],bt[oo];
for(int i=;i<oo;i++)
C[i]=at[i]=bt[i]=;
at[]=;
bt[]=;
for(int i=;i<oo;i++)
at[i]=at[i-]*a,bt[i]=bt[i-]*b;
if(type==)
{//sin(ax+b)
double tmp=;
for(int i=;i<oo;i+=)
{
for(int j=;j<=i;j++)
C[j]+=tmp*at[j]*bt[i-j]/fac[j]/fac[i-j];
tmp*=-1.00;
}
return ;
}
if(type==)
{//e^(ax+b)
for(int i=;i<oo;i++)
{
for(int j=;j<=i;j++)
C[j]+=fac[i]/fac[j]/fac[i-j]*at[j]*bt[i-j]/fac[i];
}
return ;
}
if(type==)
{
C[]=b;
C[]=a;
return ;
}
}
}tr[N];
int n,m;
double fac[];
char tmp[];
bool whc(int spc)
{
return tr[tr[spc].fa].rs==spc;
}
void pushup(int spc)
{
for(int i=;i<oo;i++)
tr[spc].f[i]=tr[spc].C[i];
if(lll)
for(int i=;i<oo;i++)
tr[spc].f[i]+=tr[lll].f[i];
if(rrr)
for(int i=;i<oo;i++)
tr[spc].f[i]+=tr[rrr].f[i];
return ;
}
void trr(int spc)
{
if(!spc)
return ;
std::swap(lll,rrr);
tr[spc].lzt^=;
return ;
}
void pushdown(int spc)
{
if(tr[spc].lzt)
{
trr(lll);
trr(rrr);
tr[spc].lzt=;
}
return ;
}
void recal(int spc)
{
if(!tr[spc].anc)
recal(tr[spc].fa);
pushdown(spc);
return ;
}
void rotate(int spc)
{
int f=tr[spc].fa;
bool k=whc(spc);
tr[f].ch[k]=tr[spc].ch[!k];
tr[spc].ch[!k]=f;
if(tr[f].anc)
{
tr[f].anc=;
tr[spc].anc=;
}else
tr[tr[f].fa].ch[whc(f)]=spc;
tr[spc].fa=tr[f].fa;
tr[f].fa=spc;
tr[tr[f].ch[k]].fa=f;
pushup(f);
pushup(spc);
return ;
}
void splay(int spc)
{
recal(spc);
while(!tr[spc].anc)
{
int f=tr[spc].fa;
if(tr[f].anc)
{
rotate(spc);
return ;
}
if(whc(spc)^whc(f))
rotate(spc);
else
rotate(f);
rotate(spc);
}
return ;
}
void access(int spc)
{
int lst=;
while(spc)
{
splay(spc);
tr[rrr].anc=;
tr[lst].anc=;
rrr=lst;
lst=spc;
pushup(spc);
spc=tr[spc].fa;
}
return ;
}
void Mtr(int spc)
{
access(spc);
splay(spc);
trr(spc);
return ;
}
void split(int x,int y)
{
Mtr(x);
access(y);
splay(y);
return ;
}
void link(int x,int y)
{
Mtr(x);
tr[x].fa=y;
return ;
}
bool together(int x,int y)
{
split(x,y);
while(tr[y].ls)
y=tr[y].ls;
return x==y;
}
void cut(int x,int y)
{
split(x,y);
tr[x].fa=;
tr[x].anc=true;
tr[y].ls=;
pushup(y);
return ;
}
int main()
{
scanf("%d%d",&n,&m);
scanf("%s",tmp);
fac[]=;
for(int i=;i<oo;i++)
{
double x=i;
fac[i]=fac[i-]*x;
}
for(int i=;i<=n;i++)
{
tr[i].Insert();
tr[i].Taylor(fac);
tr[i].anc=;
}
while(m--)
{
scanf("%s",tmp+);
if(tmp[]=='a')
{
int a,b;
scanf("%d%d",&a,&b);
a++,b++;
link(a,b);
}else if(tmp[]=='d')
{
int a,b;
scanf("%d%d",&a,&b);
a++,b++;
cut(a,b);
}else if(tmp[]=='m')
{
int x;
scanf("%d",&x);
x++;
splay(x);
tr[x].Insert();
tr[x].Taylor(fac);
}else{
int a,b;
scanf("%d%d",&a,&b);
double x;
scanf("%lf",&x);
a++,b++;
if(!together(a,b))
puts("unreachable");
else{
double ret=tr[b].val(x);
printf("%.8e\n",ret);
}
}
}
return ;
}
BZOJ5020: [THUWC 2017]在美妙的数学王国中畅游(LCT,泰勒展开,二项式定理)的更多相关文章
- BZOJ5020 [THUWC 2017]在美妙的数学王国中畅游LCT
题意很明显是要用LCT来维护森林 难点在于如何处理函数之间的关系 我们可以根据题目给的提示关于泰勒展开的式子 将三种函数变成泰勒展开的形式 因为$x∈[0,1]$ 所以我们可以将三个函数在$x_0=0 ...
- bzoj5020 & loj2289 [THUWC 2017]在美妙的数学王国中畅游 LCT + 泰勒展开
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=5020 https://loj.ac/problem/2289 题解 这个 appear 和 d ...
- bzoj 5020(洛谷4546) [THUWC 2017]在美妙的数学王国中畅游——LCT+泰勒展开
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5020 https://www.luogu.org/problemnew/show/P4546 ...
- bzoj5020: [THUWC 2017]在美妙的数学王国中畅游
Description 数学王国中,每个人的智商可以用一个属于 [0,1]的实数表示.数学王国中有 n 个城市,编号从 0 到 n−1 ,这些城市由若干座魔法桥连接.每个城市的中心都有一个魔法球,每个 ...
- loj2289 [THUWC 2017]在美妙的数学王国中畅游(LCT+Taylor展开)
link 题目大意: 你需要维护一个树 每个点都有个sin(ax+b)或exp(ax+b)或ax+b 你需要维护一些操作:连边.删边.修改某个点的初等函数.询问某条树链上所有函数带入某个值后权值和或不 ...
- bzoj 5020: [THUWC 2017]在美妙的数学王国中畅游【泰勒展开+LCT】
参考:https://www.cnblogs.com/CQzhangyu/p/7500328.html --其实理解了泰勒展开之后就是水题呢可是我还是用了两天时间来搞懂啊 泰勒展开是到正无穷的,但是因 ...
- 【BZOJ5020】[THUWC 2017]在美妙的数学王国中畅游 泰勒展开+LCT
[BZOJ5020][THUWC 2017]在美妙的数学王国中畅游 Description 数字和数学规律主宰着这个世界. 机器的运转, 生命的消长, 宇宙的进程, 这些神秘而又美妙的过程无不可以用数 ...
- 【BZOJ5020】[LOJ2289]【THUWC2017】在美妙的数学王国中畅游 - LCT+泰勒展开
咕咕咕?咕咕咕! 题意: Description 数字和数学规律主宰着这个世界. 机器的运转, 生命的消长, 宇宙的进程, 这些神秘而又美妙的过程无不可以用数学的语言展现出来. 这印证了一句古老的名言 ...
- [THUWC 2017]在美妙的数学王国中畅游
bzoj5020 \[答案误差只要小于 10^{-7}\] 题解 Taylor展开式: \[若f(x)的n阶导数在[a, b]内连续,则f(x)在x_{0}\in[a, b]可表示为\] \[f(x) ...
随机推荐
- java音乐播放之IO流处理
这个类仅仅能一直播放.知道音乐结束. 比AudioCilp要好一点. import java.io.*; import javax.sound.sampled.*; public class Test ...
- 项目:rbac 基于角色的权限管理系统;
- 简单示意流程图 - RBAC分析: - 基于角色的权限管理: - 权限等于用户可以访问的URL: - 通过限制URL来限制权限: - RBAC表结构组成: from django.db impor ...
- Gallery滑动一页(一个Item)效果
本文主要介绍如何使用Gallery只滑动一页以及其实现原理. Demo APK 可以方便的查看效果,在各大应用商店搜索 trinea android 下载即可,如:Google Play. 可运行代码 ...
- phantomjs 设置代理
phantomjs 可通过以下设置代理ip #coding=utf-8import osimport reimport timeimport requestsfrom scrapy.selector ...
- javaScript 预编译过程浅尝
javaScript 预编译过程 1.创建AO对象(Activation Object) AO{ a: } 2.找形参和变量声明,将变量和形参作为AO属性名,值为undefined AO{ a:und ...
- linux安装lrzsz支持rz从windows上传文件到linux
1.下载lrzsz wget https://wangxuejin-data-1252194948.cos.ap-shanghai.myqcloud.com/lrzsz-0.12.20.tar.gz ...
- 直接修改Android软件数据库来改变软件设置实例一则
昨天把K860i刷了机,刷到了最新的CyanogenMod 10.1,使用起来各种流畅舒服,不过却由于内外置SD卡的挂载点的改变,造成了一些困扰,现记录如下. 平时里由于极少把手机连接 ...
- 树莓派3b+ wifi无线连接
一.配置文件启动wifi 配置 /etc/network/interfaces 文件实现,但在图形界面上并没有wifi图标可以选择,这种方法不够灵活,后面连接其它的wifi都要去修改配置文件 首先打开 ...
- 【Uva 242】Stamps and Envelope Size
[Link]: [Description] 给你n个集合; 每个集合都包含一些不同面额的邮票; (每种邮票都当做有无限张) 然后给你一封信上最多能贴的邮票张数S; 问你,哪一个集合的邮票; 能够贴出来 ...
- WMI获取进程CPU占用率
Monitor % Process CPU Usage (specific process) http://www.tek-tips.com/viewthread.cfm?qid=395765 for ...