2026.8.16 模拟赛10

· · 个人记录

2026.8.16 模拟赛10

一、比赛基本情况

比赛日期:2026.8.15

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

比赛得分:0pts

比赛排名:rk2

二、比赛整体回顾

开题顺序:T1\ ~(约30min\ 0pts) - T2\ ~(约0min\ 0pts) - T3\ ~(约30min\ 0pts) - T4\ ~(约30min\ 0pts)

三、题目复盘

T1: U432312 排行榜

本题得分:0pts

初始思路:

骗分

考场解题过程:

骗分

考场代码:

#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,m;
struct node{
    int val,id;
}a[N];
bool flag=0;
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>>m;
    for(int i=1;i<=n;i++){
        int x,y,z;
        cin>>x>>y>>z;
        a[i].val=x+y+z;
        a[i].id=i;
    }
    sort(a+1,a+n+1,cmp);
    while(m--){
        char op;
        int x,y,k;
        cin>>op>>x;
        if(op=='q'){
            for(int i=1;i<=n;i++){
                if(a[i].id==x){
                    cout<<i<<endl;      
                }
            }
        }else{
            cin>>y>>k;
            for(int i=1;i<=n;i++){
                if(a[i].id==x){
                    a[i].val+=k;        
                    break;
                }
            }
            sort(a+1,a+n+1,cmp);
        }
    }
    return 0;
} 

赛后题解:

类似插入排序那一道题。

每次排一次序显然会超时。

所以我们用来一个pos数组来记录每个数当前的位置。

所以在查询的时候只要O(1)输出即可。

因为保证了修改操作不会太多,所以我们在修改操作里面更新。

从pos[x]的位置分别向前和向后遍历一次,如果大小顺序不对或者大小对了但没按输入顺序排序就交换一次。

#### 补题代码: ```cpp #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; struct node{ int T[5]; 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].T[1]>>t[i].T[2]>>t[i].T[3]; t[i].val=t[i].T[1]+t[i].T[2]+t[i].T[3]; 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--){ char op; int x,y,k; cin>>op; cin>>x; if(op=='u'){ cin>>y>>k; t[pos[x]].T[y]=k; t[pos[x]].val=t[pos[x]].T[1]+t[pos[x]].T[2]+t[pos[x]].T[3]; 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{ cout<<pos[x]<<endl; } } return 0; } ``` ### T2: P1077 [NOIP 2012 普及组] 摆花 #### 本题得分:$0pts

初始思路:

以为是数学题,但没推出来公式

考场解题过程:

没写

考场代码:

无

赛后题解:

多重背包板子。

补题代码:

#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
const int N=105,mod=1e6+7;
int n,m;
int a[N];
int dp[N][N];
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];
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=m;j++){
            for(int k=0;k<=min(j,a[i]);k++){
                dp[i][j]=(dp[i][j]+dp[i-1][j-k])%mod;
            }
        }
    }          
    cout<<dp[n][m];
    return 0;
}

T3: P4822 [BJWC2012] 冻结

本题得分:0pts

初始思路:

dijkstra,没调出来

考场解题过程:

dijkstra

考场代码:

#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=1e3+5;
int n,m,k;
int mini=1e18;
struct node{
    int id,SP,val;
    bool operator<(node y)const{
        return val>y.val;
    }
};
int dis[N][55];
bool vis[N];
vector<node> G[N];
void dijkstra(int st){
    memset(dis,0x3f,sizeof(dis));
    memset(vis,0,sizeof(vis));
    priority_queue<node> Q;
    Q.push({st,0,0});
    dis[st][0]=0;
    while(Q.size()){
        int x=Q.top().id;
        Q.pop();
        if(vis[x]==1){
            continue;
        }
        vis[x]=1;
        for(int i=0;i<G[x].size();i++){
            int v=G[x][i].id;
            int w=G[x][i].val;
            int E=0;
            if(dis[x][E]+w<dis[v][E]){
                dis[v][E]=dis[x][E]+w;
                Q.push({v,E,dis[v][E]});
            }
        }
    } 
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>k;
    for(int i=1;i<=m;i++){
        int u,v,w;
        cin>>u>>v>>w;
        G[u].push_back({v,0,w});
        G[v].push_back({u,0,w});
    }
    dijkstra(1);
    for(int i=0;i<=k;i++){
//      cout<<dis[n][i]<<' ';
        mini=min(mini,dis[n][i]);
    }
    cout<<mini;
    return 0;
}

赛后题解:

多一个维度的dijkstra,记录用来几次减半机会

答案就是所有的dis[en][k]

补题代码:

#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=5e4+5;
int n,m,k;
int mini=1e18;
int st,en;
struct node{
    int id,val,w;
    bool operator<(node y)const{
        return w>y.w;
    }
};
int dis[N][55];
bool vis[N][55];
vector<node> G[N];
void dijkstra(int s){
    memset(dis,0x3f,sizeof(dis));
    memset(vis,0,sizeof(vis));
    priority_queue<node> Q;
    Q.push({s,0,0});
    dis[s][0]=0;
    while(Q.size()){
        int x=Q.top().id;
        int c=Q.top().val;
        Q.pop();
        if(vis[x][c]==1){
            continue;
        }
        vis[x][c]=1;
        for(int i=0;i<G[x].size();i++){
            int v=G[x][i].id;
            int w=G[x][i].w;
            if(dis[v][c]>dis[x][c]+w){
                dis[v][c]=dis[x][c]+w;  
                Q.push({v,c,dis[v][c]});   
            }
            if(c<k&&dis[v][c+1]>dis[x][c]+w/2){
                dis[v][c+1]=dis[x][c]+w/2;   
                Q.push({v,c+1,dis[v][c+1]});  
            }
        }
    } 
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>k;
    for(int i=1;i<=m;i++){
        int u,v,w;
        cin>>u>>v>>w;
        G[u].push_back({v,0,w});
        G[v].push_back({u,0,w});
    }
    dijkstra(1);
    for(int i=0;i<=k;i++){
        mini=min(mini,dis[n][i]);
        // cout<<dis[n][i]<<' ';
    }
    cout<<mini; 
    return 0;
}

T4: P6121 [USACO16OPEN] Closing the Farm G

本题得分:0pts

初始思路:

把关闭谷仓当成倒叙开启谷仓,用并查集维护开启的谷仓个数,判断并查集里面的个数够不够就好了

但没调出来

考场解题过程:

按思路

考场代码:

无

赛后题解:

和我想的一样

补题代码:

#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 fa[N];
int siz[N];
int stop[N];
bool ans[N];
bool vis[N];
vector<int> G[N];
int find(int x){
    if(fa[x]==x){
        return x;
    }
    return fa[x]=find(fa[x]);
}
void uniSet(int x,int y){
    x=find(x);
    y=find(y);
    if(x!=y){
        fa[x]=y;
        siz[y]+=siz[x];
        siz[x]=siz[y];
    }
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        fa[i]=i;
        siz[i]=1;
    }
    for(int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for(int i=1;i<=n;i++){
        cin>>stop[i];
    }
    for(int i=n;i>=1;i--){
        vis[stop[i]]=1;
        for(int j=0;j<G[stop[i]].size();j++){
            int v=G[stop[i]][j];
            if(vis[v]==1){
                uniSet(stop[i],v);
            }
        }
        int root=find(stop[i]);
        if(siz[root]==n-i+1){
            ans[i]=1;
        }else{
            ans[i]=0;
        }
    }
    for(int i=1;i<=n;i++){
        if(ans[i]==1){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

The end!