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) ...
随机推荐
- 理解Linq查询
using System; using System.Linq; static class Program { static double Square(double n) { Console.Wri ...
- mybatis :与Spring MVC 的集成
用mybatis与Spring mvc 的方式集成起来,源码在本文结尾处下载.主要有以下几个方面的配置1. web.xml 配置 spring dispatchservlet ,比如为:mvc-dis ...
- 2015北京网络赛 Couple Trees 倍增算法
2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道. 解法来自 q ...
- c# 引用ConfigurationManager 类
c#添加了Configuration;后,竟然找不到 ConfigurationManager 这个类,后来才发现:虽然引用了using System.Configuration;这个包,但是还是不行 ...
- React开发实时聊天招聘工具 -第五章 需求分析
Axios的使用 axios.get('/data') .then(res=>{ if(res.status==200) this.setState(data:res.data) })
- JQ each 各种标签
类选择器: $("input[class=class1]").each(function(){ alert($(this).val()); }); ID选择器: $("i ...
- 【Codeforces Round #459 (Div. 2) D】MADMAX
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] f[x][y][z][2] 表示第一个人到了点x,第二个人到了点y,当前轮的字母(1..26),当前轮到谁走的情况下,谁赢. 写个记 ...
- php, hhvm与odp & Unix domain Socket方式
接上一篇,复习一下 启动php或hhvm: php/sbin/php-fpm start hhvm/bin/hhvm_control start 启动nginx或lighttpd: webserver ...
- USACO milk
/* ID:kevin_s1 PROG:milk LANG:C++ */ #include <iostream> #include <string> #include < ...
- Handle-postDelayed 延迟操作
今天在工作的时候,遇到了一个方法,是关于Handle来实现延时操作的,自己写了一个小demo,学习总结如下 xml <?xml version="1.0" encoding= ...