Codeforces Round 958 (Div. 2) A - C题

视频讲解:Codeforces Round 958 (Div. 2) A - C题_哔哩哔哩_bilibili

讲解都在视频里噢 (o′┏▽┓`o) 

A - Diverse Game

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

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n, m;
        cin >> n >> m;
        vector<vector<int>> a(n, vector<int>(m));
        for (auto &i : a)
            for (auto &j : i)
                cin >> j;
        if (n == 1 && m == 1)
        {
            cout << -1 << endl;
            continue;
        }
		if (n % 2 && m % 2)
			swap(a[0][0], a[n / 2][m / 2]);
        for (int i = n - 1; i >= 0; i--)
        {
            for (int j = m - 1; j >= 0; j--)
                cout << a[i][j] << ' ';
            cout << endl;
        }
    }
}

B - Fun Game

#include<bits/stdc++.h>
using namespace std;
int n;
string s, t;

bool solve()
{
    string temp(n, ' ');
    for (int i = 0; i < n; i++)
        temp[i] = (s[i] - '0') ^ (t[i] - '0') + '0';
    int cnt1 = 0, cnt2 = 0;
    for (auto i : temp)
    {
        if (i == '1')
            break;
        cnt1++;;
    }
    for (auto i : s)
    {
        if (i == '1')
            break;
        cnt2++;;
    }
    if (cnt2 > cnt1)
        return false;
    return true;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        cin >> n >> s >> t;
        cout << (solve() ? "YES\n" : "NO\n");
    }
}

C - Hungry Games

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

signed main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n, x, ans = 0;
        cin >> n >> x;
        vector<int> a(n), prefix(n), next(n), dp(n + 3, 0);
        for (auto &i : a)
            cin >> i;
        prefix[0] = a[0];
        for (int i = 1; i < n; i++)
            prefix[i] = prefix[i - 1] + a[i];
        for (int i = 0; i < n; i++)
        {
            int l = i - 1, r = n;
            while (l + 1 < r)
            {
                int mid = (r + l) >> 1;
                int curPrefix = (i == 0) ? prefix[mid] : prefix[mid] - prefix[i - 1];
                if (curPrefix > x)
                    r = mid;
                else
                    l = mid;
            }
            if (r == n)
                next[i] = -1;
            else
                next[i] = r;
        }
        for (int i = n - 1; i >= 0; i--)
            dp[i] = next[i] == -1 ? 0 : 1 + dp[next[i] + 1];
        for (int i = 0; i < n; i++)
            ans += n - i - dp[i];
        cout << ans << endl;
    }
}

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值