Codeforces Round 934 (Div. 2) ( 3 / 6)

本文介绍了三个C++编程题目,包括MEXGame1中的求最小出现次数、破坏桥梁问题的解决方案以及相等异或操作。每个题目展示了不同的逻辑和数据结构应用。
摘要由CSDN通过智能技术生成

A  Destroying Bridges

#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,k;
    cin>>n>>k;
    if(k>=n-1)cout<<'1'<<endl;
    else cout<<n<<endl;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

B  Equal XOR

#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,k,x;
    map<int,int>mp1,mp2;
    cin>>n>>k;
    // vector<int>a(2*n);
    for(int i=0;i<n;i++){
        cin>>x;
        mp1[x]++;
    }
    for(int i=0;i<n;i++){
        cin>>x;
        mp2[x]++;
    }
    vector<int>l,r;
    for(int i=1;i<=n;i++){
        if(mp1[i]==2&&l.size()<2*k)l.push_back(i),l.push_back(i);
        if(mp2[i]==2&&r.size()<2*k)r.push_back(i),r.push_back(i);
    }
    while(l.size()>r.size())l.pop_back();
    while(r.size()>l.size())r.pop_back();
    for(int i=1;i<=n;i++){
        if(mp1[i]==mp2[i]&&l.size()<2*k)
            l.push_back(i),r.push_back(i);
    }
    for(auto i:l)cout<<i<<' ';
    cout<<endl;
    for(auto i:r)cout<<i<<' ';
    cout<<endl;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

C  MEX Game 1

#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n,x,ma=0;
    bool t=1;
    cin>>n;
    map<int,int>m;
    for(int i=0;i<n;i++)cin>>x,m[x]++,ma=max(ma,x);
    for(int i=0;i<=ma;i++){
        if(m[i]==0){cout<<i<<endl;return ;}
        if(m[i]==1&&t==0){cout<<i<<endl;return ;}
        else if(m[i]==1)t=0;
    }
    cout<<ma+1<<endl;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值