当前位置: 首页 > news >正文

[THUWC 2017]在美妙的数学王国中畅游

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;
}

转载于:https://www.cnblogs.com/cjoieryl/p/8206717.html

相关文章:

  • Spring框架之我见(三)——IOC、AOP
  • 敏捷公关
  • js操作时间(持续更新)
  • 好文分享--java企业架构 spring mvc +mybatis + KafKa+Flume+Zookeeper分布式架构
  • MySQL 千万 级数据量根据(索引)优化 查询 速度
  • mariadb主从复制/半同步复制
  • 我的速读理解
  • Tengine 结合 lua 防御 cc ***
  • 常见高危安全漏洞
  • ajax发送post请求
  • 类型信息
  • mysql如何执行关联查询与优化
  • HP C7000刀片服务器实战3:Redhat Linux 6.8操作系统安装
  • webview 设置夜间模式
  • 004 Ubuntu上安装truffle
  • ECMAScript入门(七)--Module语法
  • FastReport在线报表设计器工作原理
  • github从入门到放弃(1)
  • nfs客户端进程变D,延伸linux的lock
  • RedisSerializer之JdkSerializationRedisSerializer分析
  • Shadow DOM 内部构造及如何构建独立组件
  • v-if和v-for连用出现的问题
  • 服务器之间,相同帐号,实现免密钥登录
  • 给第三方使用接口的 URL 签名实现
  • 猴子数据域名防封接口降低小说被封的风险
  • 浏览器缓存机制分析
  • 网页视频流m3u8/ts视频下载
  • 如何在 Intellij IDEA 更高效地将应用部署到容器服务 Kubernetes ...
  • 专访Pony.ai 楼天城:自动驾驶已经走过了“从0到1”,“规模”是行业的分水岭| 自动驾驶这十年 ...
  • # Swust 12th acm 邀请赛# [ K ] 三角形判定 [题解]
  • #鸿蒙生态创新中心#揭幕仪式在深圳湾科技生态园举行
  • #中国IT界的第一本漂流日记 传递IT正能量# 【分享得“IT漂友”勋章】
  • $.extend({},旧的,新的);合并对象,后面的覆盖前面的
  • ( 10 )MySQL中的外键
  • (LNMP) How To Install Linux, nginx, MySQL, PHP
  • (SpringBoot)第七章:SpringBoot日志文件
  • (附源码)springboot金融新闻信息服务系统 毕业设计651450
  • (三)c52学习之旅-点亮LED灯
  • (四)搭建容器云管理平台笔记—安装ETCD(不使用证书)
  • (原創) 未来三学期想要修的课 (日記)
  • .net 4.0 A potentially dangerous Request.Form value was detected from the client 的解决方案
  • .NET Core WebAPI中封装Swagger配置
  • .net 托管代码与非托管代码
  • .NET企业级应用架构设计系列之结尾篇
  • .NET设计模式(11):组合模式(Composite Pattern)
  • @hook扩展分析
  • [Angularjs]ng-select和ng-options
  • [BJDCTF2020]The mystery of ip1
  • [C# 开发技巧]如何使不符合要求的元素等于离它最近的一个元素
  • [codeforces]Recover the String
  • [codevs1288] 埃及分数
  • [Effective C++读书笔记]0012_复制对象时勿忘其每一部分
  • [git] windows系统安装git教程和配置
  • [IE技巧] IE8中HTTP连接数目的变化
  • [leetcode top100] 0924 找到数组中消失的数,合并二叉树,比特位计数,汉明距离