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) ...
随机推荐
- Redis封装之String
RedisBase类 /// <summary> /// RedisBase类,是redis操作的基类,继承自IDisposable接口,主要用于释放内存 /// </summary ...
- 2.cocos设置背景图片
在bool HelloWorld::init()中加入如下代码 auto bg = Sprite::create("1.jpg"); if (bg) { bg->setPos ...
- intellij idea 13
mac版 http://pan.baidu.com/s/1c0zjWU8 intellij idea 编辑器之于程序员,犹如鞋之于女人.有的女人赤脚都漂亮,性感. 有的女人赤身都没人看.程序员亦如此. ...
- 【2017 Multi-University Training Contest - Team 1 1001】Add More Zero
[Link]: [Description] 让你求最大的k; 使得 10^k<=2^m-1 [Solution] 求出2^m-1的位数就好; [lg(2^m-1)] = lg(2^m) = m* ...
- Springboot源码——应用程序上下文分析
前两篇(Spring MVC源码——Root WebApplicationContext 和 Spring MVC源码——Servlet WebApplicationContext)讲述了spring ...
- 洛谷 P3887 [GDOI2014]世界杯
P3887 [GDOI2014]世界杯 题目描述 3014年世界杯足球赛就要开始了!作为卫冕冠军中国足球队的教练,手下每位球员都是猛将,如何摆出最强的11人阵容也是一件幸福的烦恼事啊. 众所周知,足球 ...
- ShopNC【B2B2C】多用户电商平台系统,带WAP,微商城,圈子,门户
<ShopNC[B2B2C]多用户电商平台系统,带WAP,微商城,圈子,门户> 早上发了套ShopNC B2B2C多用户商城2014商业版,带微商城,但不带圈子.WAP.圈子和门户,如今发 ...
- IsoAlgo3d三维管道软件
IsoAlgo3d三维管道软件 eryar@163.com 1.概述 IsoAlgo3d三维管道软件主要用于将目前国际主流管道设计软件AVEVA PDMS和Intergraph SmartPlatn3 ...
- jquery19 ajax()
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- jquery源码01---(2880 , 3042) Callbacks : 回调对象 : 对函数的统一管理
// optionsCache : { 'once memory' : { once : true , memory : true } } var optionsCache = {}; // once ...