跳到正文

个人记录

2026.8.7 模拟赛2

AC_Goose约 16 分钟
原文
文章信息与版本

文章信息

发布
2026年8月8日
收录
2026年8月8日
更新
2026年11月17日
篇幅
约 16 分钟

版本

  1. v1当前

2026.8.6 模拟赛1

一、比赛基本情况

比赛日期:2026.8.6

比赛时长:14:00 14:00\ ~  16:00  2h\ 16:00\ ~2h

比赛得分:124pts124pts

比赛排名:rk4rk4

二、比赛整体回顾

开题顺序:T1  T1\ ~(约40min 24pts40min\ 24pts) - T2  T2\ ~(约40min 95pts40min\ 95pts) - T3  T3\ ~(约20h 5pts20h\ 5pts) - T4  T4\ ~(约20min 0pts20min\ 0pts)

三、题目复盘

T1: P10188 [USACO24FEB] Milk Exchange B

本题得分:24pts24pts
初始思路:

我发现了一个性质,我们可以把样例建成一个图,图中有两部分,一个是环,一个是链。其中,环因为是互换牛奶,所以不会损失牛奶,但链的部分会按照一个方向一直传递牛奶,如果遇到了环,就会损失牛奶。我们只要先拓扑排序记录每个环的位置,枚举每一个位置,往左边和右边扩展,用sumsum记录链上的牛奶数量,ans+=min(m,sum)ans+=min(m,sum)即可。

考场解题过程:

按思路写了,但可能是想复杂了,处理了很多细节(可能没用?),总之就是写成了120行的屎山: (

考场代码:
C++
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=2e5+5;
int n,m;
int ans;
int sum;
int len;
string s;
int a[N];
int in[N];
bool all=1;
bool vis[N];
queue<int> Q;
vector<int> G[N];
void topu(){
	for(int i=1;i<=n;i++){
		if(in[i]==0){
			Q.push(i);
		}
	} 
	while(Q.size()){
		int x=Q.front();
		Q.pop();
		for(int i=0;i<G[x].size();i++){
			int v=G[x][i];
			in[v]--;
			if(in[v]==0){
				Q.push(v);
			} 
		}
	}
	for(int i=1;i<=n;i++){
		if(in[i]!=0){
			vis[i]=1;
		}
	} 
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	cin>>s;
	len=s.size();
	s='#'+s;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=1;i<=len;i++){
		if(i!=len&&s[i]!=s[i+1]){
			all=0;
		}
		if(s[i]=='L'){
			if(i==1){
				in[n]++;
				G[i].push_back(n);
			}else{
				in[i-1]++;
				G[i].push_back(i-1);
			}
		}else{
			if(i==n){
				in[1]++;
				G[n].push_back(1);
			}else{
				in[i+1]++;
				G[i].push_back(i+1);
			}
		}
	}
	if(all==1){
		cout<<sum;
		return 0;
	} 
	topu();
	for(int i=1;i<=n;i++){
		if(vis[i]==1){
			if(vis[i+1]==1){
				int sum=0;
				for(int j=i-1;;){
					if(s[j]=='R'){
						sum+=a[j];
						if(j!=1){
							j--;
						}else{
							j=n;
						}
					}else{
						break;
					}
				}
				ans+=min(sum,m);
//				cout<<i<<' '<<min(sum,m)<<endl;
			}else{
				int sum=0;
				for(int j=i+1;;){
					if(s[j]=='L'){
						sum+=a[j];
						if(j!=n){
							j++;
						}else{
							j=1;
						}
					}else{
						break;
					}
				}
				ans+=min(sum,m);
//				cout<<i<<' '<<min(sum,m)<<endl;
			}
//			cout<<ans<<endl;
		} 
	}
	cout<<sum-ans;
	return 0;
} 
赛后题解:

思路大差不差,但是简洁了一点,删掉了很多不必要的处理。

补题代码:
C++
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=2e5+5;
int n,m;
int ans;
int sum;
char a[N];
int b[N];
int getl(int x){
    if(x==1){
        return n;
    }else{
        return x-1;
    }
}
int getr(int x){
    if(x==n){
        return 1;
    }else{
        return x+1;
    }
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
        sum+=b[i];
    }
    for(int i=1;i<=n;i++){
        int sum1=0,sum2=0;
        if(a[i]=='R'&&a[getr(i)]=='L'){
            int tmp=i;
            while(a[getl(tmp)]=='R'){
                tmp=getl(tmp);
                sum1+=b[tmp];
            }
            tmp=getr(i);  
            while(a[getr(tmp)]=='L'){
                tmp=getr(tmp);  
                sum2+=b[tmp];
            }
            ans+=min(sum1, m)+min(sum2, m);  
        }
    }
    cout<<sum-ans;
	return 0;
} 

T2: P7076 [CSP-S 2020] 动物园

本题得分:95pts95pts
初始思路:

依旧神秘性质起手。

我发现我们只要把每个养了的动物的编号二进制算出来,如果这一行要买饲料,就用一个needneed数组装起来。最后枚举每一个位,如果这一行已经买了饲料或者本就不需要买饲料,就ans∗=2ans*=2,最后输出的时候减去一个nn。

考场解题过程:

一模一样的过程!

为什么出题人卡long long!
考场代码:
C++
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=1e6+5;
int n,m,c,k;
int ans=1;
struct node{
	int p,q;
}t[N];
int a[N];
int num[70],cnt;
int have[70];
map<int,bool> mp;
map<int,bool> need;
void get(int x){
	memset(num,0,sizeof(num));
	cnt=0;
	while(x!=0){
		num[cnt++]=x%2;
		x/=2;
	}
	int limit=cnt;
	for(int i=1;i<=k-limit-1;i++){
		num[++cnt]=0;
	}
	for(int i=cnt;i>=0;i--){
//		cout<<num[i];
		if(num[i]==1&&mp[i]==1){
			need[i]=1;
//			cout<<i<<' ';
//			cout<<i<<' '<<mp[i]<<endl;
		}
	}
//	cout<<endl;
}
signed main(){
//	freopen("zoo3.in","r",stdin);
//	freopen("zoo3.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>c>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=m;i++){
		cin>>t[i].p>>t[i].q;
		mp[t[i].p]=1;
	}
	for(int i=1;i<=n;i++){
		get(a[i]);
	}
	for(int i=70;i>=70-k+1;i--){
		int now=70-i;
//		cout<<now<<' ';
		if(need[now]==1||mp[now]==0){
//			cout<<i<<' ';
			ans*=2;
		}
	}
	cout<<ans-n;
	return 0;
}
赛后题解:

特判卡long long情况并使用unsigned long long

补题代码:
C++
#include<bits/stdc++.h>
#define int unsigned long long
// #define ull unsigned long long
#define endl '\n'
using namespace std;
int n,m,c,k;
int ans=1;
int sum;
int cnt;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>c>>k;
	for(int i=1;i<=n;i++){
        int a;
        cin>>a;
        sum|=a;
	}
	for(int i=1;i<=m;i++){
        int p,q;
        cin>>p>>q;
        cnt|=(1ull<<p);
	}
    for(int i=0;i<=k-1;i++){
        if((sum&(1ull<<i))!=0||(cnt&(1ull<<i))==0){
            ans*=2;  
        }
    }
    if(ans==0&&n==0&&k==64){
        cout<<"18446744073709551616";
    }else{
        cout<<ans-n;
    }
	return 0;
}

T3: U298378 买零食

本题得分:5pts5pts
初始思路:

没看出来是区间dp: (

于是排序之后直接从左到右买。

考场解题过程:

排序。模拟。

考场代码:
C++
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=2005;
int n;
int ans;
int a[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		ans+=(a[n]-a[i]);
	}
	cout<<ans;
	return 0;
}
赛后题解:

区间dp板子。

dp[i][j]:dp[i][j]: 买区间ii到jj的零食的最小花费。转移时看先买最左边第ii个便宜还是先买最右边第jj个便宜。

没了。

补题代码:
C++
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=2005;
int n;
int a[N];
int dp[N][N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
        cin>>a[i];  
    }
    sort(a+1,a+n+1);  
    for(int len=2;len<=n;len++){
        for(int i=1;i+len-1<=n;i++){
            int j=i+len-1;  
            dp[i][j]=min(dp[i][j-1],dp[i+1][j])+abs(a[i]-a[j]);  
        }
    } 
    cout<<dp[1][n]; 
	return 0;
}

T4:

本题得分:0pts0pts
初始思路:

二分+数位dp

考场解题过程:

刚写完二分部分就结束了。

考场代码:

无

赛后题解:

确实是二分+数位dp

补题代码:
C++
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=1005;
int ask,y;
int dp[N][N];
int num[1000005],cnt;
int dfs(int pos,int sum,int allzero,int limit){
    if(pos==0){
        return sum;
    }
    if(limit==0&&allzero==0&&dp[pos][sum]!=-1){
        return dp[pos][sum];
    }
    int tmp=limit?num[pos]:9;
    int ans=0;
    for(int i=0;i<=tmp;i++){
        if(allzero==1&&i==0){
            ans+=dfs(pos-1,0,1,0);
        }else if(i==ask){
            ans+=dfs(pos-1,sum+1,allzero&&i==0,limit&&i==tmp);
        }else{
            ans+=dfs(pos-1,sum,allzero&&i==0,limit&&i==tmp);
        }    
    }
    if(limit==0&&allzero==0){
        dp[pos][sum]=ans;
    }
    return ans;
}
bool check(int x){
    memset(num,0,sizeof(num));
    cnt=0;
    while(x!=0){
        num[++cnt]=x%10;
        x/=10;
    }
    memset(dp,-1,sizeof(dp));
    return dfs(cnt,0,1,1)<=y;
}
void find(){
    int l=0-1,r=1e18+1;
    while(l+1<r){
        int mid=(l+r)/2;
        if(check(mid)){
            l=mid;
        }else{
            r=mid;
        }
    }
    cout<<l;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cin>>ask>>y;
    find();
	return 0;
}

the end!

原文