Codeforces Round 908 (Div. 2)

Codeforces Round 908 (Div. 2)

A

获取对战的最后一个即为胜者

#include <bits/stdc++.h>

using namespace std;

void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << s[n-1] << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while(T --){
        solve();
    }
    return 0;
}

B

只要有两个出现两次以上的数字即为合法
对着两个数字分别使用两种组合即可

#include <bits/stdc++.h>

using namespace std;
const int N = 1e5;

int a[N];

void solve()
{
    int n;
    unordered_map<int, int> m;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        m[a[i]]++;
    }
    int s1 = -1, s2 = -1, cnt = 0;
    for (auto &&[x, y] : m)
    {
        if (y >= 2)
        {
            if (s1 == -1)
                s1 = x;
            else
                s2 = x;
            cnt++;
            if (cnt == 2)
                break;
        }
    }
    if (cnt < 2)
    {
        cout << "-1\n";
        return;
    }
    vector<int> k(5);
    for (int i = 1; i <= n; i++)
    {
        if (a[i] == s1)
        {
            if (k[1] == 0)
            {
                cout << "1 ";
                k[1] = 1;
            }
            else if (k[2] == 0)
            {
                cout << "2 ";
                k[2] = 1;
            }
            else
                cout << "1 ";
        }
        else if (a[i] == s2)
        {
            if (k[3] == 0)
            {
                cout << "1 ";
                k[3] = 1;
            }
            else if (k[4] == 0)
            {
                cout << "3 ";
                k[4] = 1;
            }
            else
                cout << "1 ";
        }
        else
        {
            cout << "1 ";
        }
    }
    cout << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

C

执行操作后, x总是数组的最后一个元素。
若x大于n则非法
旋转操作至多进行min(n,k)次

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;

void solve()
{
    int n, k;
    cin >> n >>  k;
    vector<int>a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int last = n - 1;
    for (int i = 0; i < min(k,n); i++)
    {
        if (a[last] > n)
        {
            cout << "No\n";
            return;
        }
        last += n - a[last];
        if (last >= n)
            last -= n;
    }
    cout << "Yes\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

D

b数组顶多贡献一次反向排序再归并就是最小的方案

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;

void solve()
{
    int n , m;
    cin >> n >> m;
    vector<int> a(n), b(m), c(n + m);
    for(int i = 0 ; i < n ; i ++)cin >> a[i];
    for(int i = 0 ; i < m ; i ++)cin >> b[i];
    sort(b.rbegin() , b.rend()); //反向排序
    merge(a.begin(), a.end(), b.begin(), b.end(),c.begin(), greater<int>()); //归并排序
    for (int i = 0; i < n + m; i++) {
        cout << c[i] << ' ';
    }
  cout << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

  • 14
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值