【牛客训练记录】牛客周赛 Round 80

训练情况

赛后反思

玩了一两天发现自己水平直接下降一个档次,简单的C题模拟没写出来

A题

直接判断剩下还能放几个棋子,如果小于零就无法放置,否则直接输出即可

点击查看代码
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'

using namespace std;

void solve(){
    int x,y; cin>>x>>y;
    if(x - y < 0) cout<<"quit the competition!"<<endl;
    else cout<<x-y<<endl;
}

signed main(){
    // int T; cin>>T; while(T--)
    solve();
    return 0;
}

B题

直接排序贪心,两两之间绝对值最小,我们直接排序后一对一对求和即可

点击查看代码
#include <bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

void solve(){
    int n; cin>>n;
    vector<int> a(2*n + 1);
    for(int i = 1;i<=2*n;i++) cin>>a[i];
    sort(a.begin() + 1,a.end());
    int ans= 0;
    for(int i = 2;i<=2*n;i+=2) ans += a[i] - a[i-1];
    cout<<ans<<endl;
}

signed main(){
    // int T; cin>>T; while(T--)
    solve();
    return 0;
}
posted @ 2025-02-10 01:15  MNNUACM_2024ZY  阅读(33)  评论(0)    收藏  举报