• [THUWC2017]在美妙的数学王国中畅游


    description

    BZOJ

    solution

    (LCT)+泰勒展开。
    顺便练了一下(LCT)

    求导数错了一个地方改了好久,果然还是数学不行啊。

    Code

    #include<bits/stdc++.h>
    #include<algorithm>
    #include<iostream>
    #include<cstdlib>
    #include<iomanip>
    #include<cstring>
    #include<complex>
    #include<vector>
    #include<cstdio>
    #include<string>
    #include<bitset>
    #include<ctime>
    #include<cmath>
    #include<queue>
    #include<stack>
    #include<map>
    #include<set>
    #define Cpy(x,y) memcpy(x,y,sizeof(x))
    #define Set(x,y) memset(x,y,sizeof(x))
    #define FILE "a"
    #define mp make_pair
    #define pb push_back
    #define RG register
    #define il inline
    using namespace std;
    typedef unsigned long long ull;
    typedef vector<int>VI;
    typedef long long ll;
    typedef double dd;
    const dd eps=1e-7;
    const int mod=1e9+7;
    const int N=100010;
    const int M=1000010;
    const int inf=2147483647;
    const ll INF=1e18+1;
    const ll P=100000;
    il ll read(){
    	RG ll data=0,w=1;RG char ch=getchar();
    	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
    	if(ch=='-')w=-1,ch=getchar();
    	while(ch<='9'&&ch>='0')data=data*10+ch-48,ch=getchar();
    	return data*w;
    }
    
    il void file(){
    	srand(time(NULL)+rand());
    	freopen(FILE".in","r",stdin);
    	freopen(FILE".out","w",stdout);
    }
    
    const int K=17;
    int n,m;ll fac[K];char st[20];
    int fa[N],s[2][N],rv[N],cal[N],top;
    dd v[N][20],sum[N][20];
    #define isr(i) (s[1][fa[i]]==i)
    #define isroot(i) (s[0][fa[i]]!=i&&s[1][fa[i]]!=i)
    il void update(int i){
    	for(RG int k=0;k<K;k++)
    		sum[i][k]=v[i][k]+sum[s[0][i]][k]+sum[s[1][i]][k];
    }
    il void reverse(int i){swap(s[0][i],s[1][i]);rv[i]^=1;}
    il void pushdown(int i){
    	if(!rv[i])return;rv[i]=0;
    	if(s[0][i])reverse(s[0][i]);
    	if(s[1][i])reverse(s[1][i]);
    }
    il void rot(int i){
    	int j=fa[i],k=fa[j];bool b=isr(i);
    	if(!isroot(j))s[isr(j)][k]=i;fa[i]=k;
    	if(s[!b][i])fa[s[!b][i]]=j;s[b][j]=s[!b][i];
    	s[!b][i]=j;fa[j]=i;update(j);
    }
    il void splay(int i){
    	cal[++top]=i;
    	for(RG int x=i;!isroot(x);x=fa[x])cal[++top]=fa[x];
    	while(top)pushdown(cal[top--]);
    	for(RG int j=fa[i];!isroot(i);rot(i),j=fa[i])
    		if(!isroot(j))isr(i)^isr(j)?rot(i):rot(j);
    	update(i);
    }
    il void access(int x){
    	for(RG int y=0;x;y=x,x=fa[x])splay(x),s[1][x]=y,update(x);
    }
    il void makeroot(int x){access(x);splay(x);reverse(x);}
    il int findroot(int x){
    	access(x);splay(x);while(s[0][x])x=s[0][x];return x;
    }
    il void split(int x,int y){makeroot(x);access(y);splay(y);}
    il void link(int x,int y){makeroot(x);fa[x]=y;}
    il void cut(int x,int y){split(x,y);fa[x]=s[0][y]=0;update(y);}
    
    il void func(int f,dd a,dd b,dd *g){
    	dd r=1,s,c;if(f==1)c=cos(b),s=sin(b);if(f==2)c=exp(b);
    	for(RG int i=0;i<K;i++){
    		if(f==1){g[i]=((i&1)?c:s)*r;if(i%4>=2)g[i]=-g[i];}
    		else if(f==2)g[i]=c*r;
    		else if(f==3){g[i]=0;if(!i)g[i]=b;if(i==1)g[i]=a;}
    		if(f!=3)g[i]/=fac[i];r*=a;
    	}
    }
    il void modify(int u,int f,dd a,dd b){
    	access(u);splay(u);func(f,a,b,v[u]);update(u);
    }
    il dd query(int u,int v,dd x){
    	RG dd ret=0,r=1;split(u,v);
    	for(RG int i=0;i<K;i++,r=r*x)ret+=sum[v][i]*r;
    	return ret;
    }
    
    int main()
    {
    	fac[0]=1;for(RG int i=1;i<K;i++)fac[i]=fac[i-1]*i;
    	n=read();m=read();scanf("%s",st+1);
    	RG dd a,b,x,as;
    	for(RG int i=1,f;i<=n;i++){
    		f=read();scanf("%lf%lf",&a,&b);func(f,a,b,v[i]);
    	}
    	for(RG int i=1,u,v,c,f;i<=m;i++){
    		scanf("%s",st+1);
    		if(st[1]=='a'){u=read()+1;v=read()+1;link(u,v);}
    		if(st[1]=='d'){u=read()+1;v=read()+1;cut(u,v);}
    		if(st[1]=='m'){
    			c=read()+1;f=read();scanf("%lf%lf",&a,&b);
    			modify(c,f,a,b);
    		}
    		if(st[1]=='t'){
    			u=read()+1;v=read()+1;scanf("%lf",&x);
    			if(findroot(u)!=findroot(v))puts("unreachable");
    			else printf("%.8lf
    ",query(u,v,x));
    		}
    	}
    	return 0;
    }
    
    
  • 相关阅读:
    旋转加载loading和点点加载loadingdemo
    css 点点加载demo
    gulp——myself配置
    AngularJS官网seed目录结构
    CSS content换行技术实现字符animation loading效果
    gulp入门与一些基本设置
    css 图标 旋转中
    【图文教程】WebStorm下使用Github下载以及上传代码
    gulp-uglify的使用
    面试题 ——— 二维数组的查找
  • 原文地址:https://www.cnblogs.com/cjfdf/p/9677903.html
Copyright © 2020-2023  润新知