CSP202203 全部题解

这篇博客提供了CSP202203比赛的全题解,涵盖了未初始化警告、出行计划、计算资源调度器、通信系统管理和博弈论与石子合并等题目,主要使用C++编程语言,涉及基础算法和数据结构的应用,适合大学生学习参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

都是些简单题,但我看网上好像没有全题解,写一篇造福大学生。

未初始化警告

签到

#include <iostream>
#include <cstdio>
using namespace std;
#define N 100005
int n, k, ans = 0;
bool vis[N];
int main() {
   
	ios::sync_with_stdio(false);
	cin >> n >> k;
	vis[0] = true;
	for(int i = 1; i <= k; ++i) {
   
		int x, y;
		cin >> x >> y;
		if(!vis[y]) ++ans;
		vis[x] = true;
	}
	cout << ans;
	return 0; 
} 

出行计划

签到

#include <iostream>
#include <cstdio>
using namespace std;
#define N 400005
int n, m, k; 
int d[N];
int main() {
   
	ios::sync_with_stdio(false);
	cin >> n >> m >> k;
	for(int i = 1; i <= n; ++i) {
   
		int t, c;
		cin >> t >> c;
		int left = max(1, t - c + 1);
		++d[left], --d[t + 1];
	}
	for(int i = 1; i <= N - 5; ++i) d[i] += d[i - 1];
	
	for(int i = 1; i <= m; ++i) {
   
		int q;
		cin >> q;
		cout << d[q + k] << endl;
	}
	return 0;
}

计算资源调度器

简单模拟

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;
#define N 3005
int n, m, g;

int f[N], a[N], na[N], pa[N], paa[N];
bool paar[N];

struct node {
   
	int cnt, l, id; 
	
	bool operator <(const node &x) const {
   
		return cnt == x.cnt ? id < x.id : cnt < x.cnt;
	}
}nd[N], p[N];

vector < int > seg[N], task[N];
bool used[N], tmp[N];

void nodeFrd(int na) {
   
	for(int i = 0; i < seg[na].size(); ++i) {
   
		int u = seg[na][i];
		used[u] = false;
	}
	for(int i = 1; i <= n
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值