C/C++教程

AtCoder Beginer Contest 236 ABCD签到

本文主要是介绍AtCoder Beginer Contest 236 ABCD签到,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

A.chukodai

拼手速

#include <bits/stdc++.h>
using namespace std;

inline void solve(){
    string s; cin >> s;
    int a, b; cin >> a >> b;
    for(int i = 0; i < s.size(); i++){
        if(i == a - 1) cout << s[b - 1];
        else if(i == b - 1) cout << s[a - 1];
        else cout << s[i];
    }
}

signed main(){
    solve();
    return 0;
}

B.Who is missing?

拼手速

#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;
int a[N];

inline void solve(){
    int n = 0; cin >> n;
    for(int i = 1; i <= 4 * n - 1; i++){
        int num = 0; cin >> num;
        a[num]++;
    }
    for(int i = 1; i <= n; i++)
        if(a[i] < 4){ cout << i << endl; return; }
}

signed main(){
    solve();
    return 0;
}

C.Route Map

拼手速

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
string s[N];
map<string, int> t;

inline void solve(){
    int n, m; cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> s[i];
    for(int i = 1; i <= m; i++){
        string ss; cin >> ss;
        t[ss] = 1;
    }
    for(int i = 1; i <= n; i++){
        if(t.count(s[i])) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

signed main(){
    solve();
    return 0;
}

D.Dance

暴力枚举即可, 1 ≤ N ≤ 8 1\leq N \leq 8 1≤N≤8。

#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int N = 100;
int a[N][N], vis[1000], n, cnt, ans, tmp = 0;

void dfs(int now){
    if(now == (n << 1 | 1)){ if (cnt == (n << 1) && tmp > ans) ans = tmp; return; }
    if(vis[now]){ dfs(now + 1); return; }
    for(int i = now + 1; i <= 2 * n; i++){
        if(vis[i] == 1) continue;
        vis[i] = vis[now] = 1, tmp ^= a[now][i], cnt += 2;
        dfs(now + 1);
        vis[i] = vis[now] = 0, tmp ^= a[now][i], cnt -= 2;
    }
}

inline void solve(){
    cin >> n;
    for(int i = 1; i <= 2 * n - 1; i++)
        for(int j = i + 1; j <= 2 * n; j++) cin >> a[i][j];
    dfs(1);
    cout << ans << endl;
}

signed main(){
    solve();
    return 0;
}

这篇关于AtCoder Beginer Contest 236 ABCD签到的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!