2022.4.15

2022/4/15 23:42:59

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

AtCoder Beginner Contest 236

A - chukodai

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e5+10,INF=1e9;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int a, b;
    cin >> a >> b;
    swap(s[a - 1], s[b - 1]);
    cout << s;

    return 0;
}

B - Who is missing?

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e5+10,INF=1e9;
int vis[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= 4 * n - 1;i++)
    {
        int x;
        cin >> x;
        vis[x]++;
    }
    for (int i = 1; i <= n;i++)
    {
        if(vis[i]==3)
        {
            cout << i << '\n';
            break;
        }
    }
        return 0;
}

C - Route Map

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<string,int> psi;
const int N=1e5+10,INF=1e9;
psi a[N];
map<string, int> mp;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    for (int i = 1; i <= n;i++)
    {
        cin >> a[i].first;
        a[i].second = 0;
    }
    for (int i = 1;i<=m;i++)
    {
        string s;
        cin >> s;
        mp[s] = 1;
    }
    for (int i = 1; i <= n;i++)
    {
        if(mp[a[i].first])
        {
            cout << "Yes\n";
        }
        else
            cout << "No\n";
    }
        return 0;
}

D - Dance

两两配对选择舞伴,以为dfs会超时实际上是不会的,需要注意当一对舞伴被选了后,后面的就不能再重复选其中的任意一个了。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=15+10,INF=1e9;
int a[N][N],ans,n;
bool vis[N];
void dfs(int now,int res)
{
    if(now==0)
    {
        ans = max(res, ans);
        return;
    }
    if(vis[now])
    {
        dfs(now - 1, res);
        return;
    }

    for (int i = 1; i <= n ;i++)
    {
        if(!vis[i]&&i!=now)//当前的层数和选的数都没有没选过
        {
            vis[i] = 1;
            vis[now] = 1;
            dfs(now - 1, res ^ a[now][i]);
            vis[i] = 0;//还原现场
            vis[now] = 0;
        }
    }
    return;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    n = n * 2;
    for (int i = 1; i < n;i++)
    {
        for (int j = i+1; j <= n;j++)
        {
            cin >> a[i][j];
            a[j][i] = a[i][j];
        }
    }
    dfs(n-1, 0);
    cout << ans;
    return 0;
}



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


扫一扫关注最新编程教程