暑假集训CSP提高模拟8

一看见题目列表就吓晕了,还好我是体育生,后面忘了

唉这场比赛没啥好写的,要不就是太难要不就是太简单要不就是拉出去写在专题里了

A. 基础的生成函数练习题

考虑到只有奇偶性相同才能尝试加二,因此先用加一调平奇偶性,再直接加而就行了.

#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c;long long ans=0;
	cin>>a>>b>>c;
	int a2=a&1,b2=b&1,c2=c&1;
	if(a2==c2 and a2==b2);
	else if(a2==c2 and a2!=b2){
		ans++;a++,c++;
	}
	else if(a2==b2 and a2!=c2){
		ans++;a++,b++;
	}
	else if(b2==c2 and a2!=b2){
		ans++;b++,c++;
	}
	ans+=(3ll*max({a,b,c})-a-b-c)/2;
	cout<<ans<<endl;
}

B.简单的拉格朗日反演练习题

我:学长你卡线段树有什么深意吗
学长:没卡线段树,那是你常数写大了

但是线段树把原题过了,详见 这个专题

C.容易的多元拉格朗日反演练习题

\(S = \sum_{1\le i\le n} a_i\)\(S_A\) 为 Alice 擦掉的数之和,\(S_B\) 为 Bob 擦掉的数之和。
记一个长为 \(m\) 序列 \(b_i\) 的邻项差分 \(\text{diff }b = (b_2 - b_1) + (b_4 - b_3) + \cdots + (b_m - b_{m-1})\)

首先转化题意。条件 \(l \le S_A \le r\) 可以通过整体乘 \(2\)\(S\) 转化为 \(2L - S \le S_A - S_B \le 2R - S\)。随后设 \(x = S - (l + r)\),整体加 \(x\) 后变为 \(l - r \le x + S_A - S_B \le r - l\),即 \(|x + S_A - S_B| \le r - l\)

因此有转化后的问题:
给定整数 \(x\)。两人轮流操作,每次选择一个没有选过的数字 \(a_i\)。在 Alice 的回合,置 \(x=x + a_i\),而在 Bob 的回合置 \(x=x - a_i\)。最终的分数即为 \(x\) 的绝对值。Alice 的目标是最小化这个值,而 Bob 的目标是最大化它。求当两方都采取最优策略情况下的赢家。

不妨假设 \(a_i\) 升序排列。我们断言,最终的分数可以通过如下方式求得:

  • 选择整数 \(p\),将 \(p, p + x, a_1, a_2,\cdots, a_n\) 升序排列得到 \(A_i\)。令 \(p\) 的答案为 \(\text{diff }A\) 的值。
  • 最终的分数即为所有可能的 \(p\) 的答案中的最小值。

容易发现 \(p\) 所有对答案有贡献的取值为 \(p = a_i\)。对于 \(p\) 的某一确定取值可以在 \(O(n)\) 的时间复杂度内计算答案,取其中最小值作为最终分数即可

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,a[5001];
vector<int>ans;
signed main(){
	int cases;cin>>cases;while(cases--){
		int l,r;
		cin>>n>>l>>r;
		int sum=0;
		for(int i=1;i<=n;++i){
			cin>>a[i];
			sum+=a[i];
		}
		sum-=l+r;
		sort(a+1,a+n+1);
		int ret=LLONG_MAX,now;
		for(int i=1;i<=n;++i){
			ans.clear();
			now=0;
			for(int j=1;j<=n;++j){
				if(i!=j){
					ans.push_back(a[j]);
				}
			}
			ans.insert(lower_bound(ans.begin(),ans.end(),a[i]+sum),a[i]+sum);
			for(int j=0;j<=(int)ans.size()-1;j+=2){
				now+=ans[j+1]-ans[j];
			}
			ret=min(ret,now);
		}
		cout<<(abs(ret)<=r-l?"Alice":"Bob")<<endl;
	}
} 

D. 朴素的抽象代数题

不是,你们怎么都不打暴力的啊

放一个暴力辅助理解题面吧

#include<bits/stdc++.h>
using namespace std;
unsigned long long l;
class _function{
	private:
		int a[26];
	public:
		int&operator[](int id){
			return a[id];
		}
		inline void equal_func(){
			for(int i=0;i<(int)l;++i){
				a[i]=i;
			}
		}
		_function operator+(_function A){
			_function ans;
			for(int i=0;i<(int)l;++i){
				ans[i]=A[this->operator[](i)];
			}
			return ans;
		}
		void operator+=(_function A){
			*this=*this+A;
		}
		void print(){
			for(int i=0;i<(int)l;++i){
				cout<<a[i]<<" ";
			}
			cout<<endl;
		}
		string func(string x){
			string ans;
			for(char i:x){
				ans.push_back(this->a[i-'a']+'a');
			}
			return ans;
		}
		void operator =(std::vector<int>x){
			for(int i=0;i<=(int)x.size()-1;++i){
				a[i]=x[i];
			}
		}
}fu[3001];
typedef unsigned long long ull;
ull n,m,q,STR_LEN,seed1,seed2,FREQ,MAX_X;
int f[26],LEN;
ull xorShift128Plus(){
    ull k3=seed1,k4=seed2;
    seed1=k4;
    k3^=(k3<<23);
    seed2=k3^k4^(k3>>17)^(k4>>26);
    return seed2+k4;
}
template<typename T>
void my_shuffle(T __first,T __last){
    if(__first==__last) return;
    for(T __i=__first+1;__i!=__last;++__i)
        std::iter_swap(__i,__first+xorShift128Plus()%(int(__i-__first)+1));
}
vector<int>fun;
struct act{
	bool type;
	int a;
	string b;
}ac[3001];
string ans[100001];
ull getHash(string ch){
    ull hsh=0;
    for (int i=0;i<=(int)ch.length()-1;i++){
		hsh=hsh*131+ch[i];
	}
    return hsh;
}
signed main(){
    scanf("%llu %llu %llu %llu %llu %llu %llu %llu %llu",
            &n,&m,&q,&l,&seed1,&seed2,&STR_LEN,&FREQ,&MAX_X);
	fu[0].equal_func();
    for(int i=0;i<(int)l;i++) f[i]=i;
    for(int i=1;i<=(int)m;i++){
        my_shuffle(f,f+l);
        fun.clear();
        for(int i=0;i<(int)l;i++){
        	fun.push_back(f[i]);
        }
        fu[i]=fun;
    }
    for(int i=1;i<=(int)n;i++){
        if(xorShift128Plus()%FREQ<=1){
        	ac[i]={0,(int)(xorShift128Plus()%m+1),};
        }
		else{
            LEN=STR_LEN-(xorShift128Plus()&7);
            ac[i].type=1;
            for(int j=1;j<=LEN;j++){
            	ac[i].b.push_back(xorShift128Plus()%l+'a');
            }
        }
    }
    unsigned long long xcnt=0,nowact=1;
    while(1){
    	if(ac[nowact].type==0){
	   		fu[0]+=fu[ac[nowact].a];
		}
		else{
			ans[++xcnt]=fu[0].func(ac[nowact].b);
			if(xcnt==MAX_X) break;
		}
		nowact++;
		if(nowact>n) nowact-=n;
	}
	unsigned long long anss=0;
    for(int i=1;i<=(int)q;i++){
    	unsigned long long res=getHash(ans[xorShift128Plus()%MAX_X+1])-i;
        anss^=res;
    }
    cout<<anss<<endl;
}

后记

$\large\text{老婆可爱捏}$

posted @ 2024-07-26 20:57  HaneDaniko  阅读(32)  评论(3编辑  收藏  举报