跳到正文

个人记录

CSP - S 2024 模拟赛五补题报告

SgtTree_约 8 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年4月18日
篇幅
约 8 分钟

版本

  1. v1当前
CSP − S  2024  模拟赛五  补题报告2024年8月5日−2024年8月5日by   XXXCSP \ - \ S \ \ 2024 \ \ 模拟赛五 \ \ 补题报告 \\ 2024年8月5日 - 2024年8月5日 \\ by \ \ \ XXX

一、做题情况

  • 第一题比赛 100100 / 100100 ,赛后通过

  • 第二题比赛 6060 / 100100 ,赛后通过

  • 第三题比赛 2020 / 100100 ,赛后未通过

  • 第四题比赛 00 / 100100 ,赛后未通过

  • 比赛得分 180180 / 400400 ,赛后补题 240240 / 400400

二、比赛概况

断网测试,成绩真实,虽然对我来说没有区别(但是有人似乎因此爆零了?)

T1 很简单,但还是严谨的推了一下式子,测了大样例。T2 没想出正解,就对着数据范围写了 60%60\% 的部分分,不错的是部分分都用状压写法拿到了。T3 想的是背包,但是一看数据范围发现好像不行,于是就首先排除了正解。。想到贪心,但是有顺序限制,就想写随机化,但是随机化的打乱序列也不会,就按照四中排序规则都贪了一遍,小样例都过了,大样例都错了。就仿照着 T2 的状压打了个奇奇怪怪的 O(n!2nlogn)O(n! 2^n log n) ,应该有 4040 分的,但是实测 2020 ,赛后发现是 输入数据的格式错了 !警钟撅烂!T4 不会,没了。

三、题解报告

T1:残缺的序列(seq)

题面:

给定你 1∼n1 \sim n 的数字的一种排列中的 mm 个数,求出字典序最小的原序列

做法:

将所有不在已知序列中的数字取出来,从小到大排序;枚举原序列的每一个位置,将比这个位置小的数都加在当前位置之前,可以保证字典序最小

附:AC代码

C++
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
const int maxn=1e5+10;
int n,m,a[maxn];
bool vis[maxn];
priority_queue<int,vector<int>,greater<int> >q;
int main(){
	freopen("seq.in","r",stdin);
	freopen("seq.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(nullptr);cout.tie(nullptr);
	cin>>n>>m;
	for(int i=1;i<=m;i++)cin>>a[i];
	for(int i=1;i<=m;i++)vis[a[i]]=1;
	for(int i=1;i<=n;i++)if(!vis[i])q.push(i);
	a[m+1]=n+1;
//	cout<<"---> ";
//	for(int i=1;i<=n;i++)cout<<vis[i]<<" ";
//	cout<<"\n---> ";
//	while(q.size()){cout<<q.top()<<" ";q.pop();}
//	cout<<"\n";
	for(int i=1;i<=m+1;i++){
		while(!q.empty()&&q.top()<a[i]){
			cout<<q.top()<<"\n";
			q.pop();
		}
		if(i!=m+1)cout<<a[i]<<"\n";
	}
	return 0;
}
/*
5 3
1 4 2

*/

T2:均匀的括号(bracket)

题面:

定义空串的合法的且深度为 00

若序列 AA 是合法的且深度为 kk ,则 (A)(A) 也是合法的且深度为 k+1k+1

若序列 AA、BB 是合法的,且深度分别为 hAh_A、hBh_B ,则序列 ABAB 的深度为 max⁡(hA,hB)\max(h_A,h_B)

给你一个合法的括号序列,问最少操作几次可以使深度不超过 LL

做法:

贪心,时时维护,每次修改是改一对,代码自行理解

附:AC代码

  • 暴力状压 60pts60 pts
C++
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int n,limit,ans=INT_MAX;
int sum;
int deep,now,top;
string s,t;
//stack<char>stk;
int get_sum(int x){
	sum=0;
	while(x){
		sum+=(x&1)==1;
		x>>=1;
	}
	return sum;
}
bool jug(string x){
	top=0;
	for(int i=0;i<x.size();i++){
		if(x[i]=='(')top++;
		else{
			if(!top)return 0;
			else top--;
		}
	}
	return top==0;
}
bool check(string x){
	if(!jug(x))return 0;
	deep=0,now=0,top=0;
	for(int i=0;i<x.size();i++){
		if(x[i]=='('){
			top++,now++;
			deep=max(deep,now);
		}else top--,now--;
	}
	return deep<=limit;
}
int main(){
	freopen("bracket.in","r",stdin);
	freopen("bracket.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(nullptr);cout.tie(nullptr);
	cin>>n>>limit>>s;
	if(check(s)){
		cout<<0;
		return 0;
	}
	for(int i=0;i<=(1<<n)-1;i++){
		if(get_sum(i)>=ans)continue;
		t=s;
		for(int j=0;j<n;j++){
//			cout<<(bool)(i&(1<<j));
			if(i&(1<<j)){
				if(t[j]=='(')t[j]=')';
				else t[j]='(';
			}
		}
//		cout<<"\n"<<t<<"\n";
		if(check(t)){
//			cout<<t<<"\n";
			ans=min(ans,get_sum(i));
		}
	}
	cout<<ans;
	return 0;
}
/*
20 1
(((()())(()))(()()))

*/
  • AC  CodeAC \ \ Code
C++
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int n,limit,ans,top;
string s;
int main(){
	freopen("bracket.in","r",stdin);
	freopen("bracket.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(nullptr);cout.tie(nullptr);
	cin>>n>>limit>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='(')top++;
		else top--;
		if(top<0)top+=2,ans++;
		if(top>limit)top-=2,ans++;
	}
	cout<<ans;
	return 0;
}
/*
20 1
(((()())(()))(()()))

*/

T3:辛苦的工作(work)

题面:

复盘失败,PDF无法下载

做法:

考虑把 01 背包的下标和数值互换,然后用数学算出范围,就可以极大程度地优化空间复杂度,近似板子题。

附:AC代码

C++
复盘失败,PDF无法下载

T4:精妙的分团(clique)

题面:

复盘失败,PDF无法下载

做法:

考虑符合答案的结构,只有一个团和几个互相不连边的独立集,然后枚举情况:

  1. 从团里拆一个点到独立集里

  2. 从独立集里拆一个点到团里

  3. 就没了

(我舍友 @chenhouyuan 大佬用到了与众不同的解法,直接给我同桌 @Sacred_Konnyaku_mMr 小菜鸡看懵逼了,,最终,在他的不写努力下,他没看明白。。)

附:AC代码

C++
复盘失败,PDF无法下载

四、赛后总结

这次暴力打满了,分数感觉还不错;输入格式要看清!!!

原文