一、做题情况
-
第一题比赛 / ,赛后通过
-
第二题比赛 / ,赛后通过
-
第三题比赛 / ,赛后未通过
-
第四题比赛 / ,赛后未通过
-
比赛得分 / ,赛后补题 /
二、比赛概况
断网测试,成绩真实,虽然对我来说没有区别(但是有人似乎因此爆零了?)
T1 很简单,但还是严谨的推了一下式子,测了大样例。T2 没想出正解,就对着数据范围写了 的部分分,不错的是部分分都用状压写法拿到了。T3 想的是背包,但是一看数据范围发现好像不行,于是就首先排除了正解。。想到贪心,但是有顺序限制,就想写随机化,但是随机化的打乱序列也不会,就按照四中排序规则都贪了一遍,小样例都过了,大样例都错了。就仿照着 T2 的状压打了个奇奇怪怪的 ,应该有 分的,但是实测 ,赛后发现是 输入数据的格式错了 !警钟撅烂!T4 不会,没了。
三、题解报告
T1:残缺的序列(seq)
题面:
给定你 的数字的一种排列中的 个数,求出字典序最小的原序列
做法:
将所有不在已知序列中的数字取出来,从小到大排序;枚举原序列的每一个位置,将比这个位置小的数都加在当前位置之前,可以保证字典序最小
附:AC代码
#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)
题面:
定义空串的合法的且深度为
若序列 是合法的且深度为 ,则 也是合法的且深度为
若序列 、 是合法的,且深度分别为 、 ,则序列 的深度为
给你一个合法的括号序列,问最少操作几次可以使深度不超过
做法:
贪心,时时维护,每次修改是改一对,代码自行理解
附:AC代码
- 暴力状压
#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
(((()())(()))(()()))
*/#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代码
复盘失败,PDF无法下载T4:精妙的分团(clique)
题面:
复盘失败,PDF无法下载
做法:
考虑符合答案的结构,只有一个团和几个互相不连边的独立集,然后枚举情况:
-
从团里拆一个点到独立集里
-
从独立集里拆一个点到团里
-
就没了
(我舍友 @chenhouyuan 大佬用到了与众不同的解法,直接给我同桌 @Sacred_Konnyaku_mMr 小菜鸡看懵逼了,,最终,在他的不写努力下,他没看明白。。)
附:AC代码
复盘失败,PDF无法下载四、赛后总结
这次暴力打满了,分数感觉还不错;输入格式要看清!!!