2026 SMU week1

一、前言

期末周空了好久 没有补过题,这周一开始训练时 好多知识点和相应的板都忘了,脑子也转的好慢。

感觉这周就是在补题和看以前的题和代码/(ㄒoㄒ)/~~,下周要多做一做题llllle。

二、补题

SMU Winter 2026 Personal Round 1

Problem - C - CodeforcesPalindromic Paths

题目
代码
cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3f3f3f3f3f

void solve(){
	int n,m;cin>>n>>m;
	map<int,int>mp[210];
	for(int i=2;i<=n+m;i++){
		mp[i].clear();
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			int x;cin>>x;
			if(((n+m)%2==0)&&(i+j==(n+m+2)/2)) continue;
			mp[min(i+j,n+m+2-i-j)][x]++;
		}
	}
	int ans=0;
	for(int i=2;i<=n+m+1;i++){
		int mx=0,sum=0;
		for(auto x:mp[i]){
			mx=max(mx,x.second);
			sum+=x.second;
		}
		ans+=sum-mx;
	}
	cout<<ans;
}
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int lll=1;
	cin>>lll;
	while(lll--){
		solve();
		if(lll) cout<<'\n';
	}
	return 0;
}

Problem - D - Codeforces Two Divisors

题目
代码
cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3f3f3f3f3f

const int N=1e7+10;
const int M=5e5+10;

int prime[N],cnt;
int ans1[M],ans2[M],n;
bool st[N];

inline int read(){
	int f=1,x=0;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}
	return f*x;
}
void get_prime(){
	for(int i=2;i<N;i++) {
		if(!st[i])  prime[++cnt] =i;
		for(int j=1;j<=cnt&&i*prime[j]<N;j++) {
			st[i*prime[j]]=true;
			if(i%prime[j]==0)   break;
		}
	}
}
void solve(){
	n=read();
	for(int i=1;i<=n;i++) {
		int temp=read();
		
		ans1[i]=-1,ans2[i]=-1;

		for(int j=1;prime[j]*prime[j]<=temp;j++) {
		
			int x=1;
			if(temp%prime[j]==0) {
				while(temp%prime[j]==0) {
					temp/=prime[j];
					x*=prime[j];
				}
				if(temp==1)   break;
				else{
					ans1[i]=x;
					ans2[i]=temp;
					break;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(i==n){
			cout<<ans1[i]<<'\n';
		}else{
			cout<<ans1[i]<<' ';
		}
	}
	
	for(int i=1;i<=n;i++){
		if(i==n){
			cout<<ans2[i]<<'\n';
		}else{
			cout<<ans2[i]<<' ';
		}
	}
}
signed main(){
//	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int lll=1;
//	cin>>lll;
	get_prime();
	
	while(lll--){
		solve();
		if(lll) cout<<'\n';
	}
	return 0;
}

SMU Winter 2026 Personal Round 2

Problem - C - Codeforces Mixing Water

题目
思路

分情况讨论

目标温度等于热水温度时直接选 1 杯,等于或低于冷热平均温度时选 2 杯

高于平均温度时,通过解方程找到最优奇数杯数,再比较相邻奇数杯的温差,取最小杯数。

代码
cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3f3f3f3f3f

void solve(){
	int h,c,t;
	cin>>h>>c>>t;
	if(t==h){
		cout<<1;
		return ;
	}
	if((h+c)/2.0>=t){
		cout<<2;
		return ;
	}
	
	int x=(h-t)*1.0/(2*t-c-h);
	
	double temp1=fabs(t-((x+1)*h+x*c)*1.0/(2*x+1));
	double temp2=fabs(t-((x+2)*h+(x+1)*c)*1.0/(2*(x+1)+1));
	
	if(temp1<=temp2){
		cout<<2*x+1;
		return ;
	}
	cout<<2*(x+1)+1;
	
}
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int lll=1;
	cin>>lll;
	while(lll--){
		solve();
		if(lll) cout<<'\n';
	}
	return 0;
}

Problem - D - Codeforces Yet Another Yet Another Task

题目
思路

傻了 一开始写的很麻烦 而且没写好

利用博弈论的最小最大策略 ,结合Kadane 算法(最大子段和) 思想,枚举 Bob 会移除的元素值上限(因ai​∈[−30,30]),对每个上限求 "子段和减去该上限" 的最大值,最终取所有结果的最大值。

代码
cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3f3f3f3f3f

void solve(){
	int n;cin>>n;
	int a[n+4];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int ans=0;
	for(int i=1;i<=30;i++){
		int sum=0;
		for(int j=1;j<=n;j++){
			sum+=a[j];
			if(a[j]>i||sum<0){
				sum=0;
			}else{
				ans=max(ans,sum-i);
			}
		}
	}
	cout<<ans;
		
}
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int lll=1;
//	cin>>lll;
	while(lll--){
		solve();
		if(lll) cout<<'\n';
	}
	return 0;
}

Problem - E - Codeforces Modular Stability(数论 + 组合计数)

题目
思路

数组元素均为某个数 m 的倍数且严格递增,通过组合数 统计所有满足条件的数组数量,最后用阶乘 + 逆元 计算组合数并求和。

代码
cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3f3f3f3f3f

const int N=5e5+5;
const int mod=998244353;
int fac[N],inv[N];

int qpow(int a,int n){
	int ans=1;
	while(n){
		if(n&1){
			ans=(ans*a)% mod;
		}
		a=(a*a)%mod;
		n>>=1;
	}
	return ans;
}

int C(int n, int m){
	if(n<0||m<0||m>n) return 0;
	if(m==0||m==n)  return 1;
	return ((fac[n]*inv[m])%mod*inv[n-m])%mod;
}
void init(){
	fac[0]=1;
	for(int i=1;i<N;i++)
		fac[i]=(fac[i-1]*i)% mod;
	inv[N-1]=qpow(fac[N-1],mod-2);
	for(int i=N-2;i>=0;i--)
		inv[i]=(inv[i+1]*(i+1))% mod;
}

void solve(){
	int n,k;cin>>n>>k;
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=C(n/i-1,k-1);
		ans%=mod;
	}
	cout<<ans;
}
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int lll=1;
//	cin>>lll;
	init();
	while(lll--){
		solve();
		if(lll) cout<<'\n';
	}
	return 0;
}

SMU Winter 2026 Personal Round 3

Problem - E - Codeforces Count The Blocks 数论+递推

题目
思路

先求总块数 (所有长度的块之和),再通过递推从长到短计算各长度块的数量,利用总块数减去更长块的贡献得到当前长度块数。

总块数公式为 10×n×10n−1(每位有 10 种数字,相邻不同则新增块),递推时用前缀和优化,最后倒序输出结果。

代码
cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3f3f3f3f3f

const int N=5e5+5;
const int mod=998244353;
//int fac[N],inv[N];

int qpow(int a,int n){
	int ans=1;
	while(n){
		if(n&1){
			ans=(ans*a)% mod;
		}
		a=(a*a)%mod;
		n>>=1;
	}
	return ans;
}

void solve(){
	int n;cin>>n;
	
	int ans[n+5],pre[n+5],num;
	ans[1]=pre[1]=10,num=0;
	
	for(int i=2;i<=n;++i){
		num=(num+pre[i-1]+ans[i-1])%mod;
		ans[i]=((qpow(10,i)*i)%mod-num+mod)%mod;
		pre[i]=(pre[i-1]+ans[i])%mod;
	}
	for(int i=n;i>=1;--i){
		cout<<ans[i]<<' ';
	}
}
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int lll=1;
//	cin>>lll;
	while(lll--){
		solve();
		if(lll) cout<<'\n';
	}
	return 0;
}

SMU Winter 2026 Personal Round 4

Problem - D - Codeforces Santa's Bot(概率计算 + 模逆元的组合题)

题目
思路

概率问题 啊啊啊啊 头大 概率题不是怎么会

核心是先统计每个物品被多少孩子想要,再对每个孩子计算其物品列表中所有物品的被需求次数之和

结合模逆元(快速幂实现)将分数形式的概率计算转化为模运算,累加所有孩子的贡献得到最终结果。

用数组cnt[] 统计每个物品被多少孩子想要,存储每个孩子的物品列表 tmp[x],并记录每个孩子的物品数 a[x]

  • 对每个孩子 x,计算其物品列表中所有物品的 cnt[y] 之和,temp2。
  • 该孩子的贡献为:temp2/(n*n*a[i])
  • 所有孩子的贡献相加,得到最终概率。
代码
cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3f3f3f3f3f

const int N=5e5+5;
const int mod=998244353;
//int fac[N],inv[N];

int qpow(int a,int n){
	int ans=1;
	while(n){
		if(n&1){
			ans=(ans*a)% mod;
		}
		a=(a*a)%mod;
		n>>=1;
	}
	return ans;
}

void solve(){
	int n;cin>>n;
	
	vector<int>tmp[n+5];
	int cnt[n+5];
	int a[n+5];
	int ans = 0;
	
	for(int i=1;i<=n;i++){
		cin>>a[i];
		for(int j=1;j<= a[i];j++){
			int x;cin>>x;
			tmp[i].push_back(x);
			cnt[x]++;
		}
	}
	
	for(int i = 1;i <= n;i++){
		int temp1=n*n%mod*a[i]%mod;
		int temp2=0;
		for(int j=0;j<a[i];j++){
			int k=tmp[i][j];
			temp2+=cnt[k];
		}
		ans+=temp2*qpow(temp1,mod-2);
		ans%=mod;
	}
	cout<<ans;
}
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int lll=1;
//	cin>>lll;
	while(lll--){
		solve();
		if(lll) cout<<'\n';
	}
	return 0;
}
相关推荐
yi.Ist2 小时前
关于若干基础的几何问题
c++·学习·算法·计算几何
hetao17338372 小时前
2026-01-22~23 hetao1733837 的刷题笔记
c++·笔记·算法
王燕龙(大卫)3 小时前
linuxptp时间同步
c++
郝学胜-神的一滴3 小时前
深入理解Linux套接字(Socket)编程:从原理到实践
linux·服务器·开发语言·网络·c++·程序人生·算法
程序猿编码3 小时前
高性能HTTP服务压测工具:设计思路与实现原理(C/C++代码实现)
c语言·网络·c++·网络协议·tcp/ip·http
2301_803554523 小时前
c++hpc岗位
c++
坐怀不乱杯魂3 小时前
Linux - 线程
linux·c++
diediedei3 小时前
C++中的适配器模式变体
开发语言·c++·算法
天赐学c语言4 小时前
1.25 - 零钱兑换 && 理解右值以及move的作用
c++·算法·leecode