杂题(virtual judge 热身训练)

H - Problem B. Harvest of Apples

description

There are n apples on a tree, numbered from 1 to n.
Count the number of ways to pick at most m apples.

Input

The first line of the input contains an integer T (1≤T≤105) denoting the number of test cases.
Each test case consists of one line with two integers n,m (1≤m≤n≤105).

solution:由于是算组合数的sum,这种形式很像莫队,所以我们可以用莫队来进行转移,利用下面的方程;

S ( N , M ) = ∑ i = 0 M _ C ( N , i ) S(N,M) = \sum_{i=0}^M\_C(N,i)\text{} S(N,M)=i=0M_C(N,i)
S ( N , M ) = S ( N − 1 , M ) ∗ 2 − C ( N − 1 , M ) S(N,M) = S(N-1,M)*2-C(N-1,M) S(N,M)=S(N1,M)2C(N1,M)
S ( N , M ) = S ( N , M − 1 ) + C ( N , M ) ; S(N,M) = S(N,M-1)+C(N,M); S(N,M)=S(N,M1)+C(N,M);

D - Game HDU - 5242

description

It is well known that Keima Katsuragi is The Capturing God because of his exceptional skills and experience in ‘‘capturing’’ virtual girls in gal games. He is able to play k k k games simultaneously.
One day he gets a new gal game named ‘‘XX island’’. There are n n n scenes in that game, and one scene will be transformed to different scenes by choosing different options while playing the game. All the scenes form a structure like a rooted tree such that the root is exactly the opening scene while leaves are all the ending scenes. Each scene has a value , and we use w i w_i wi as the value of the i i i-th scene. Once Katsuragi entering some new scene, he will get the value of that scene. However, even if Katsuragi enters some scenes for more than once, he will get w i w_i wi for only once.
For his outstanding ability in playing gal games, Katsuragi is able to play the game k k k times simultaneously. Now you are asked to calculate the maximum total value he will get by playing that game for k k k times.

Ambition详解_click here

J - Calculator

简化题意

给你一系列操作,从左到右,包含加法,乘法,乘方的运算;
有两个操作,一个是修改其中的一个运算,一个是输出一个整数在经过这一系列运算之后的答案。

solution: 线段树+CRT,由于模数是可以分解为几个较小的质数,所以我们用线段树维护不同模数下,不同的数字输入后的结果(w[p][q][i])表示在p节点这段计算的区间,以q为模数,当前数字为i的结果;

#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5+10;
int t,n,m;
int a[50004],b[50005],mo[10]={0,7,13,17,19},w[5][maxn][21];
int quick_pow(int x,int cnt ,int p)
{
	int ans =1;
	for(;cnt;cnt>>=1,x=x*x%p)if(cnt&1)ans = ans*x%p;
	return ans;
}
void push_up(int p,int l,int r)
{
	for(int i=1;i<=4;i++)
	for(int j=0;j<mo[i];j++)
	w[i][p][j]=w[i][p<<1|1][w[i][p<<1][j]];
}
void build(int p,int l,int r)
{
	if(l==r)
	{
		for(int i=1;i<=4;i++)
		for(int j=0;j<mo[i];j++)
		if(a[l]==1)w[i][p][j]=(j+b[l])%mo[i];
		else if(a[l]==2)w[i][p][j]=j*b[l]%mo[i];
		else w[i][p][j]=quick_pow(j,b[l],mo[i]);
		return;
	}
	int mid = l + r >>1;
	build(p<<1,l,mid);
	build(p<<1|1,mid+1,r);
	push_up(p,l,r);
}
void modify(int p,int l,int r,int x)
{
	if(l==r)
	{
		for(int i=1;i<=4;i++)
		for(int j=0;j<mo[i];j++)
		if(a[l]==1)w[i][p][j]=(j+b[l])%mo[i];
		else if(a[l]==2)w[i][p][j]=j*b[l]%mo[i];
		else w[i][p][j]=quick_pow(j,b[l],mo[i]);
		return;
	}
	int mid = l + r >> 1;
	if(x<=mid)modify(p<<1,l,mid,x);
	else modify(p<<1|1,mid+1,r,x);
	push_up(p,l,r);
	return;	
}
void exgcd(int a1,int b,int &x,int &y){
    if(b==0){x=1;y=0;return ;}
    exgcd(b,a1%b,x,y);
    int t=x;
    x=y;
    y=t-(a1/b)*y;
}
int CRT(int A){
    int M=29393,ans=0,t,x,y;
    for(int i=1; i<=4; i++){
        t=M/mo[i];
        exgcd(t,mo[i],x,y);
        ans=(ans+w[i][1][A%mo[i]]*x*t)%M;
    }
    return (ans+M)%M;
}
int main()
{
	scanf("%d",&t);
	for(int I=1;I<=t;I++)
	{
		memset(w,0,sizeof w);
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)
		{
			char x;
			cin>>x>>b[i];
			if(x=='+')a[i]=1;
			else if(x=='*')a[i]=2;
			else a[i]=3;
		}
		build(1,1,n);
		printf("Case #%d:\n",I);
		for(int i=1,loc,A,otp;i<=m;i++)
		{
			char x;
			scanf("%d",&otp);
			if(otp==1)
			{
				cin>>A;
				printf("%d\n",CRT(A));
			}
			else 
			{
				cin>>loc>>x>>A;
				if(x=='+')a[loc]=1;
				else if(x=='*')a[loc]=2;
				else a[loc]=3;b[loc]=A;
				modify(1,1,n,loc);
			}
		}
	}
}

D - Game

description

It is well known that Keima Katsuragi is The Capturing God because of his exceptional skills and experience in ‘‘capturing’’ virtual girls in gal games. He is able to play k k k games simultaneously.
One day he gets a new gal game named ‘‘XX island’’. There are n n n scenes in that game, and one scene will be transformed to different scenes by choosing different options while playing the game. All the scenes form a structure like a rooted tree such that the root is exactly the opening scene while leaves are all the ending scenes. Each scene has a value , and we use w i w_i wi as the value of the i i i-th scene. Once Katsuragi entering some new scene, he will get the value of that scene. However, even if Katsuragi enters some scenes for more than once, he will get w i w_i wi for only once.
For his outstanding ability in playing gal games, Katsuragi is able to play the game k k k times simultaneously. Now you are asked to calculate the maximum total value he will get by playing that game for k k k times.

126详解_click here
solution:树上差分/线段树/线性(不知道怎么解)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值