没错,我几乎已经把普及的重难点复习了一遍,现在把往年的CSP-J真题写一写,顺便查缺补漏

CSP-J 2025 T1 拼数

题目还是比较简单的,我这里就不想多说了(毕竟这题我在考场上A了)

#include<bits/stdc++.h>

using namespace std;

vector<char>v;
bool cmp(char a,char b){
	return a>b;
}

int main(){
	char c = getchar();
	while(c != '\n' && c != EOF){
		if(c >= '0' && c <= '9'){
			v.push_back(c);
		}
		c = getchar();
	}
	sort(v.begin(),v.end(),cmp);
	for(char ch:v){
		printf("%c",ch);
	}
	return 0;
}

CSP-J 2025 T2 座位

这题我也是在考场上A了的

#include<bits/stdc++.h>

using namespace std;

const int N = 15;
int a[N];

int main(){
	int n,m,me = 0;
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n*m;i++){
		scanf("%d",&a[i]);
		me += (a[i]>=a[1]);
	}
	int c = ceil(1.0*me/n);
	printf("%d ",c);
	me %= n;
	if(me == 0){
		me = n;
	}
	if(c%2){
		printf("%d",me);
	} else{
		printf("%d",n-me+1);
	}
	return 0;
}

CSP-J 2025 T3 异或和

我在考场上是使用前缀异或和做的,而且是不保证区间是不相交的,也是只拿了5pts(虽然已经比较接近正解了,但我也是没看明白,也是看了题解才看明白的)

具体的可以看这篇这篇题解

#include<bits/stdc++.h>
#define LL long long

using namespace std;

const LL N = 5e5+10,M = (1<<20)+10;
LL a[N],sub[N];
LL pos[M];

int main(){
	memset(pos,-1,sizeof pos);
	pos[0] = 0;
	LL n,k;
	scanf("%lld%lld",&n,&k);
	for(LL i = 1;i <= n;i++){
		scanf("%lld",&a[i]);
		sub[i] = sub[i-1]^a[i];
	}
	LL lt = 0,ans = 0;
	for(LL i = 1;i <= n;i++){
		LL x = sub[i]^k;
		if(pos[x] >= lt){
			lt = i;
			ans++;
		}
		pos[sub[i]] = i;
	}
	printf("%lld",ans);
	return 0;
}

CSP-J 2025 T4 多边形

被题目和deepseek绕晕了。这方面的题解很少,很多也看不懂。前10分可以骗出来。。。可惜考试的时候没写。

先就写这么多吧