跳到正文

个人记录

2026.8.10 模拟赛5

AC_Goose约 13 分钟
原文

这是 2026年8月12日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

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

版本

  1. v2当前
  2. v1

2026.8.10 模拟赛5

一、比赛基本情况

比赛日期:2026.8.10

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

比赛得分:81pts81pts

比赛排名:rk3rk3

二、比赛整体回顾

开题顺序:T2  T2\ ~(约1h 52pts1h\ 52pts) - T3  T3\ ~(约30min 20pts30min\ 20pts) - T1  T1\ ~(约30min 9pts30min\ 9pts)

三、题目复盘

P8266 [USACO22OPEN] Photoshoot B

本题得分:9pts9pts
初始思路:

骗分

考场解题过程:

骗分

考场代码:
C++
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;

signed main(){
//	freopen("photo.in","r",stdin);
//	freopen("photo.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout<<1;
	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;
int idx;
int cnt;
string s;
int a[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cin>>n;  
    cin>>s;  
    s="#"+s;  
    for(int i=1;i<=n;i+=2){
        if(s[i]=='G'&&s[i+1]=='H'){
            idx++;
            a[idx]=1;  
        }else if(s[i]=='H'&&s[i+1]=='G'){
            idx++;
            a[idx]=0;  
        }
    }
    for(int i=2;i<=idx;i++){
        if(a[i]!=a[i-1]){
            cnt++;
        }
    }
    if(a[idx]==1){
        cnt++;
    }
    cout<<cnt; 
	return 0;
}

T2: P7910 [CSP-J 2021] 插入排序

本题得分:52pts52pts
初始思路:

直接模拟

考场解题过程:

模拟

考场代码:
C++
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=8005;
int n,Q;
struct node{
	int val;
	int id;
}a[N],b[N];
bool cmp(node x,node y){
	if(x.val!=y.val){
		return x.val<y.val;
	}
	return x.id<y.id;
}
signed main(){
//	freopen("sort.in","r",stdin);
//	freopen("sort.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>Q;
	for(int i=1;i<=n;i++){
		cin>>a[i].val;
		a[i].id=i;
	}
	while(Q--){
		int op,x,u;
		cin>>op>>x;
		if(op==1){
			cin>>u;
			a[x].val=u;
		}else{
			for(int i=1;i<=n;i++){
				b[i].val=a[i].val;
				b[i].id=a[i].id;
			}
			sort(b+1,b+n+1,cmp);
			for(int i=1;i<=n;i++){
				if(b[i].id==x){
					cout<<i<<endl;
				}
			}
		}
	}
	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=1e6+5;
int n,q;
int op,x,v;
struct node{
    int val;
    int id;
}t[N];
int pos[N];
bool cmp(node x,node y){
    if(x.val!=y.val){
        return x.val<y.val;
    }
    return x.id<y.id;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>t[i].val;
        t[i].id=i;
    }
    sort(t+1,t+n+1,cmp);
    for(int i=1;i<=n;i++){
        pos[t[i].id]=i;
    }
    while(q--){
        cin>>op;
        if(op==1){
            cin>>x>>v;
            t[pos[x]].val=v;
            for(int i=pos[x];i>=2;i--){
                if(t[i].val<t[i-1].val||(t[i].val==t[i-1].val&&t[i].id<t[i-1].id)){
                    swap(t[i],t[i-1]);
                    swap(pos[t[i].id],pos[t[i-1].id]);
                }
            }
            for(int i=pos[x];i<=n-1;i++){
                if(t[i].val>t[i+1].val||(t[i].val==t[i+1].val&&t[i].id>t[i+1].id)){
                    swap(t[i],t[i+1]);
                    swap(pos[t[i].id],pos[t[i+1].id]);
                }
            }
        }else{
            cin>>x;
            cout<<pos[x]<<endl;
        }
    }
    return 0;
}
}

T3: P5365 [SNOI2017] 英雄联盟

本题得分:20pts20pts
初始思路:

贪心,能买多少买多少。

考场解题过程:

贪心。

考场代码:
C++
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=100005;
int n,m;
int sum=1;
int cost;
struct node{
	int k,money;
}q[N];
bool cmp(node x,node y){
	return x.money<y.money;
}
signed main(){
	// freopen("snoi.in","r",stdin);
	// freopen("snoi.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>q[i].k;
	}
	for(int i=1;i<=n;i++){
		cin>>q[i].money;
	}
	sort(q+1,q+n+1,cmp);
	for(int i=1;i<=n;i++){
		int cnt=0;
		for(int j=1;j<=q[i].k;j++){
			cnt++;
			if(sum*cnt>=m){
				cout<<cost+cnt*q[i].money;
				return 0;
			}
		}
		cost+=q[i].k*q[i].money;
		sum*=q[i].k;
	}
	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=1005;
int n,q;
int m;
int s[N],c[N];
int dp[100005];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>s[i];
	}
	for(int i=1;i<=n;i++){
		cin>>c[i];
		m+=s[i]*c[i];
	}
	dp[0]=1;
	for(int i=1;i<=n;i++){
		for(int j=m;j>=c[i];j--){
			for(int k=1;k<=s[i]&&k*c[i]<=j;k++){
				dp[j]=max(dp[j],dp[j-k*c[i]]*k);
			}
		}
	}
	for(int i=0;i<=m;i++){
		if(dp[i]>=q){
			cout<<i;
			return 0;
		}
	}
	return 0;
}

T4: 旅行商的背包

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

没时间了

考场解题过程:

无

考场代码:

无

赛后题解:

多重背包too

补题代码:
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;
int dp[N];
int w[N],val[N],cnt=0;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cin>>n>>m>>C;   
    for(int i=1;i<=n;i++){
        int a,b,c;
        cin>>a>>b>>c;   
        for(int j=0;j<=30;j++){
            if(c>(1<<j)){
                int tmp=(1<<j);   
                cnt++;  
                w[cnt]=tmp*a;  
                val[cnt]=tmp*b;   
                c-=(1<<j);
            }else{
                int tmp=c;  
                cnt++;  
                w[cnt]=tmp*a;  
                val[cnt]=tmp*b;   
                c=0;  
                break;  
            }
        }
    }
    for(int i=1;i<=cnt;i++){
        for(int j=C;j>=w[i];j--){
            dp[j]=max(dp[j],dp[j-w[i]]+val[i]);
        }
    }
    for(int i=1;i<=m;i++){
        int a,b,c;
        cin>>a>>b>>c;  
        for(int j=C;j>=0;j--){
            for(int k=0;k<=j;k++){
                dp[j]=max(dp[j],dp[j-k]+a*k*k+b*k+c);  
            }
        }
    }
    cout<<dp[C]; 
	return 0;
}

The end!