2024CSP游记

SZXcoco / 2024-12-14 / 原文

本文同步至本人博客园

2024CSP游记

众所周知,2024CSP第二轮非专业组能力等级认证将于2024.10.26(星期六)举行

关于本人

初中生,今年第一次参加CSP的复赛。只过了J组

赛前

赛前一星期,教练让我们每天都到机房训练,整整一星期。

文化课pass

作业pass

共做10+套模拟

出行状况&&时间线

本人坐标ZJ,考点在杭州师范大学(下沙校区)。

周五

15:30放学

16:00出发

17:18:12日落

17:50到达

19:30吃完饭回到酒店,开始复习,定居全季酒店(下沙奥莱店)。

22:20睡觉

周六(比赛当天)

06:30起床

07:20到达学校

07:45进考场

08:20发放解压密码

08:25发放试题密码

08:30比赛开始

12:00比赛结束

14:40回家

16:20回到家

比赛相关(附本人赛时代码)

T1poker

#include<bits/stdc++.h>
using namespace std;
int n, ans, cnt;
map<string, int>mp;
int main(){
	freopen("poker.in", "r", stdin);
	freopen("poker.out", "w", stdout);
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		string s;
		cin >> s;
		if(mp[s] == 0)mp[s] = 1, cnt++;
	}
	cout << 52 - cnt << '\n';
	return 0;
}

T2explore

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int T, n, m, k, fx, fy, fd;
char a[MAXN][MAXN];
void output(){
	int ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(a[i][j] == 'S')ans++;
		}
	}
	cout << ans << '\n';
}
void dfs(int x, int y, int d, int cnt){
	a[x][y] = 'S';
	if(cnt == k){
		output();
		return;
	}
	if(d == 0){
		y++;
		if(x < 1 || y < 1 || x > n || y > m || a[x][y] == 'x'){
			d = (d + 1) % 4;
			y--;
		}
	}
	else if(d == 1){
		x++;
		if(x < 1 || y < 1 || x > n || y > m || a[x][y] == 'x'){
			d = (d + 1) % 4;
			x--;
		}
	}
	else if(d == 2){
		y--;
		if(x < 1 || y < 1 || x > n || y > m || a[x][y] == 'x'){
			d = (d + 1) % 4;
			y++;
		}
	}
	else if(d == 3){
		x--;
		if(x < 1 || y < 1 || x > n || y > m || a[x][y] == 'x'){
			d = (d + 1) % 4;
			x++;
		}
	}
	dfs(x, y, d, cnt + 1);
}
int main(){
	freopen("explore.in", "r", stdin);
	freopen("explore.out", "w", stdout);
	cin.tie(0)->sync_with_stdio(0);
	cin >> T;
	while(T--){
		cin >> n >> m >> k;
		cin >> fx >> fy >> fd;
		for(int i = 1; i <= n; i++){
			string s;
			cin >> s;
			for(int j = 1; j <= m; j++){
				a[i][j] = s[j - 1];
			}
		}
		dfs(fx, fy, fd, 0);
	}
	return 0;
}

T3sticks

#include<bits/stdc++.h>
using namespace std;
int T;
int a[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main(){
	freopen("sticks.in", "r", stdin);
	freopen("sticks.out", "w", stdout);
	cin.tie(0)->sync_with_stdio(0);
	cin >> T;
	while(T--){
		int n;
		cin >> n;
		if(n < 2){
			cout << -1 << '\n';
			continue;
		}
		bool ans_check = 0;
		for(int i = 1;i <= 1000000;i++){
			int k = i, ans = 0;
			while(k){
				ans += a[k % 10];
				k /= 10;
			}
			if(ans == n){
				ans_check = 1;
				cout << i << '\n';
				break;
			}
		}
		if(!ans_check)cout << -1 << '\n';
	}
	return 0;
}

T4chain

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10, MS = 1e5 + 10;
int T, l[MAXN], r[MS], c[MS];
vector<int>s[MAXN];
int main(){
	freopen("chain.in", "r", stdin);
	freopen("chain.out", "w", stdout);
	cin.tie(0)->sync_with_stdio(0);
	cin >> T;
	while(T--){
		int n, k, q;
		cin >> n >> k >> q;
		for(int i = 1; i <= n; i++){
			cin >> l[i];
			for(int j = 1; j <= l[i]; j++){
				int x;
				cin >> x;
				s[i].push_back(x);
			}
		}
		for(int i = 1; i <= q; i++){
			cin >> r[i] >> c[i];
			int x = r[i] % n;
			if(x == 0)x = n;
			int ef = upper_bound(s[x].begin(), s[x].end(), c[i]) - s[x].begin();
			if(ef > k || s[x][ef - 1] != c[i] || ef < 2)cout << 0 << '\n';
			else cout << 1 << '\n';
		}
	}
	return 0;
}

赛时

伴随着试题密码发放,考场中传来一阵阵噼噼啪啪的声音,考试开始了!

仔细浏览每一道题,键盘鼠标的敲击声扣人心弦,汗水洒满了桌面,草稿纸也布满了黑色的笔迹。

第一题直接用 map 计数,去重, \(52-计数\) 即可。

第二题第一眼就想到了 dfs ,但一看数据范围,发现会超时,所以暴力的我就写了一个回溯算法,又算了下空间。 \(16B(4个int变量) \times 10^6(k) \times 5(T) \approx 80MB\) ,太好了不会超!!

第三题,依然暴力,挂了

第四题,没写。

赛后

ZJ 11.4 出分,如上文估分所示,第一位是2,后面单调递减。二等,遗憾等明年。