• 2020CCPC 威海站 个人题解



    title : 2020CCPC 威海站 个人题解
    date : 2022-11-21
    tags : ACM,题解,练习记录
    author : Linno


    2020CCPC 威海站 个人题解

    题目链接:https://codeforces.com/gym/102798

    补题进度:6/12

    A-Golden Spirit

    条件比较多,一般来说我们都是要先把所有人送到对岸的,然后是考虑直接在这边等候老人欣赏完风景然后开始一个一个送回去还是送完过对岸送。然后如果过对岸的话要考虑另外一边是否欣赏完风景了。

    #include
    //#define int unsigned long long
    //#define int __int128
    #define int long long
    using namespace std;
    
    int read(){
    	int x=0;char ch=getchar();
    	while(!isdigit(ch)) ch=getchar();
    	while(isdigit(ch)) x=x*10ll+ch-'0',ch=getchar();
    	return x;
    }
    
    void write(int x){
    	if(x>9) write(x/10);
    	putchar(x%10+'0');
    }
    
    int n,x,t,ans;
    
    void solve(){
    	//n=read();x=read();t=read();
    	cin>>n>>x>>t;
    	int ans=4ll*n*t;
    	if(2ll*(n-1)*t<x){
    		int tmp=x-2ll*(n-1)*t;
    		if(tmp<=t){  //不需要过河 
    			ans+=tmp;	
    		}else{ //过河 
    			if(2ll*n*t>=x) ans+=t;
    			else ans+=t+x-2ll*n*t;
    		}
    	}
    //	write(ans);putchar('\n');
    	cout<<ans<<"\n";
    }
    
    signed main(){
    	ios::sync_with_stdio(0);
    	cin.tie(0);cout.tie(0);
    	int T=1;
    	cin>>T;
    	//T=read(); 
    	while(T--){
    		solve();
    	} 
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48

    C-Rencontre

    树上各块中任意两点的距离。应该有板子吧。

    #include
    #define pii pair<int,int>
    #define mk make_pair
    #define F first
    #define S second
    using namespace std;
    typedef long long ll;
    const int N=2e5+7;
    
    vector<pii>G[N];
    int n,sz[5][N],cnt[5];
    double ans=0;
    
    void dfs1(int x,int f){
    	for(auto p:G[x]){
    		int to=p.F;
    		if(to==f) continue;
    		dfs1(to,x);
    		for(int i=1;i<=3;++i) sz[i][x]+=sz[i][to];
    	}
    } 
    
    void dfs2(int x,int f){
    	for(auto p:G[x]){
    		int to=p.F,w=p.S;
    		if(to==f) continue;
    		dfs2(to,x);
    		for(int i=1;i<=3;++i){
    			for(int j=1;j<=3;++j){
    				if(i!=j) ans+=1.0*(sz[i][1]-sz[i][to])*sz[j][to]*w/cnt[i]/cnt[j]/2;
    			}
    		} 
    	}
    }
    
    signed main(){
    	scanf("%d",&n);
    	for(int i=1,u,v,w;i<n;++i){
    		scanf("%d%d%d",&u,&v,&w);
    		G[u].emplace_back(mk(v,w));
    		G[v].emplace_back(mk(u,w));
    	}
    	for(int i=1;i<=3;++i){
    		scanf("%d",&cnt[i]);
    		for(int j=1,x;j<=cnt[i];++j){
    			scanf("%d",&x);
    			++sz[i][x];
    		} 
    	}
    	dfs1(1,-1);
    	dfs2(1,-1);
    	printf("%.10lf\n",ans);
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54

    D-ABC Conjecture

    打表找一下规律就出来了。(注释了打表的代码)

    #include
    #define int long long
    using namespace std;
    const int N=1e6+7;
    
    int np[N],pri[N],cnt=0;
    void init(){
    	np[1]=1;
    	for(int i=2;i<N;++i){
    		if(!np[i]) pri[++cnt]=i;
    		for(int j=1;j<=cnt&&pri[j]*i<N;++j){
    			np[pri[j]*i]=1;
    			if(i%pri[j]==0) break;
    		}
    	}
    }
    
    int rnd(int x){
    	int res=1; 
    	for(int i=1;i<=cnt&&pri[i]*pri[i]<=x;++i){
    		if(x%pri[i]==0){
    			res*=pri[i];
    			while(x%pri[i]==0) x/=pri[i];
    		}
    	}
    	if(x>1) res*=x;
    	return res;
    }
    
    /* 
    void solve(int n){
    	for(int a=1;a<=n/2;++a){
    		int b=n-a;
    		if(rnd(a*b*n)
    
    void solve(){
    	int n;
    	cin>>n;
    	for(int i=1;i<=cnt&&pri[i]*pri[i]<=n;++i){
    		if(n%pri[i]==0){
    			int len=0;
    			while(n%pri[i]==0) n/=pri[i],len++;
    			if(len>=2){
    				cout<<"yes\n";
    				return;
    			}
    		}
    	}
    	if(n>1){
    		int bk=sqrtl(n);
    		if(bk*bk==n){
    			cout<<"yes\n";
    			return;
    		}
    	}
    	cout<<"no\n";
    }
    
    signed main(){
    	ios::sync_with_stdio(0);
    	cin.tie(0);cout.tie(0);
    	int T=1;
    	init();
    	cin>>T;
    	for(int i=1;i<=T;++i){
    	//	cout<
    		solve(); 
    	} 
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76

    G-Caesar Cipher

    线段树哈希的模板,注意合并两边的细节。

    #include
    using namespace std;
    typedef long long ll;
    const int N=5e5+7;
    const int mod=65536;
    const int mod1=1e9+7,mod2=1e9+9;
    const int base=31;
    
    ll hs[N<<2],mx[N<<2],tg[N<<2];
    ll pre[N],pw[N];
    int n,q,a[N];
    
    #define ls (p<<1)
    #define rs (p<<1|1)
    #define mid ((l+r)>>1)
    void pushup(int p,int l,int r){
    	hs[p]=(hs[ls]*pw[r-mid]%mod1+hs[rs])%mod1;
    	mx[p]=max(mx[ls],mx[rs]);
    }
    
    void pushdown(int p,int l,int r){
    	if(!tg[p]) return;
    	hs[ls]=(hs[ls]+tg[p]*pre[mid-l]%mod1)%mod1;
    	hs[rs]=(hs[rs]+tg[p]*pre[r-mid-1]%mod1)%mod1;
    	mx[ls]+=tg[p];
    	mx[rs]+=tg[p];
    	tg[ls]+=tg[p];
    	tg[rs]+=tg[p];
    	tg[p]=0;
    }
    
    void update(int p,int l,int r,int ql,int qr){
    	if(ql<=l&&r<=qr){
    		hs[p]=(hs[p]+pre[r-l])%mod1;
    		tg[p]++;
    		mx[p]++;
    		return;
    	}
    	pushdown(p,l,r);
    	if(ql<=mid) update(ls,l,mid,ql,qr);
    	if(qr>mid) update(rs,mid+1,r,ql,qr);
    	pushup(p,l,r);
    }
    
    void update_mod(int p,int l,int r){
    	if(mx[p]<mod) return;
    	if(l==r){
    		mx[p]-=mod;
    		hs[p]-=mod;
    		return;
    	}
    	pushdown(p,l,r);
    	if(mx[ls]>=mod) update_mod(ls,l,mid);
    	if(mx[rs]>=mod) update_mod(rs,mid+1,r);
    	pushup(p,l,r);
    }
    
    ll query(int p,int l,int r,int ql,int qr){
    	if(ql<=l&&r<=qr) return hs[p];
    	pushdown(p,l,r);
    	ll res=0;
    	if(qr>mid) res=(res+query(rs,mid+1,r,ql,qr))%mod1;
    	if(ql<=mid) res=(res+pw[max(0,min(qr,r)-mid)]*query(ls,l,mid,ql,qr)%mod1)%mod1;
    	return res;
    }
    
    void build(int p,int l,int r){
    	if(l==r){
    		hs[p]=mx[p]=a[l];
    		return;
    	}
    	build(ls,l,mid);
    	build(rs,mid+1,r);
    	pushup(p,l,r);
    }
    
    signed main(){
    	ios::sync_with_stdio(0);
    	cin.tie(0);cout.tie(0); 
    	pw[0]=pre[0]=1;
    	for(int i=1;i<N;++i) pw[i]=pw[i-1]*base%mod1;
    	for(int i=1;i<N;++i) pre[i]=(pre[i-1]+pw[i])%mod1;
    	cin>>n>>q;
    	for(int i=1;i<=n;++i) cin>>a[i];
    	build(1,1,n);
    	for(int i=1,op,x,y,L;i<=q;++i){
    		cin>>op>>x>>y;
    		if(op==1){
    			update(1,1,n,x,y);
    			update_mod(1,1,n);
    		}else{
    			cin>>L;
    			ll h1=query(1,1,n,x,x+L-1);
    			ll h2=query(1,1,n,y,y+L-1);
    			if(h1==h2) printf("yes\n");
    			else printf("no\n");
    		}
    	}
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100

    H-Message Bomb

    用一个st来维护每个组的人,然后对组内发送信息考虑差分即可。

    #include
    using namespace std;
    const int N=2e5+7;
    int n,m,s,ans[N],now[N];
    set<int>st[N];
    
    signed main(){
    	ios::sync_with_stdio(0);
    	cin.tie(0);cout.tie(0);
    	cin>>m>>n>>s;
    	for(int i=1,t,x,y;i<=s;++i){
    		cin>>t>>x>>y;
    		if(t==1){
    			ans[x]-=now[y];
    			st[x].insert(y);
    		}else if(t==2){
    			ans[x]+=now[y];
    			st[x].erase(y);
    		}else if(t==3){
    			--ans[x];
    			++now[y];
    		}
    	}
    	for(int i=1;i<=n;++i){
    		for(auto it=st[i].begin();it!=st[i].end();++it){
    			ans[i]+=now[*it];
    		}
    	}
    	for(int i=1;i<=n;++i) cout<<ans[i]<<"\n";
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    L-Clock Master

    运用取对数的技巧去避免精度损失。

    #include
    using namespace std;
    const int N=3e4+5;
    int read(){
    	int x=0;char ch=getchar();
    	while(!isdigit(ch)) ch=getchar();
    	while(isdigit(ch)) x=x*10ll+ch-'0',ch=getchar();
    	return x;
    }
    
    int n,vis[N],pri[N],cnt=0;
    double dp[N],g[N];
    
    void solve(){
    	n=read();
    	printf("%.9lf\n",dp[n]);
    }
    
    signed main(){
    	int T=1;
    	for(int i=2;i<=30000;++i){
    		if(vis[i]) continue;
    		pri[++cnt]=i;
    		for(int j=i;j<=30000;j+=i){
    			vis[j]=1;
    		}
    	}
    	for(int i=1;i<=120;++i){
    		for(int j=30000;j>=0;--j){
    			for(int k=pri[i];k<=j;k*=pri[i]){
    				dp[j]=max(dp[j],dp[j-k]+log(k));
    			}
    		}
    	}
    	T=read();
    	while(T--){
    		solve();
    	}
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
  • 相关阅读:
    java的实体类注解校验
    NVS 错误码对应的原因
    JavaWeb中文件上传与下载
    VB.NET 三层登录系统实战:从设计到部署全流程详解
    Jtti:Apache服务的反向代理及负载均衡怎么配置
    基于RabbitMQ构建延迟队列
    jQuery 效果- 动画
    JSTL循环Map
    一文带你梳理Python的中级知识
    高等数学_不等式合集
  • 原文地址:https://blog.csdn.net/SC_Linno/article/details/127957101