Codeforces Round 903 (Div. 3) A~E

A

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define has1 __builtin_popcount
bool isSubstring(string s1, string s2)
{
    return s1.find(s2) != string::npos;
}
void solve()
{
    int n, m;
    cin >> n >> m;
    string s, x;
    cin >> x >> s;
    int ans = 0;
    if (s == x)
    {
        cout << 0 << endl;
    }
    else
    {
        while (x.length() <= 1000)
        {
            for (int i = 0; i < x.length(); i++)
            {
                int j = 0;
                while (x[i + j] == s[j])
                {
                    j++;
                    if (j == m)
                    {
                        cout << ans << "\n";
                        return;
                    }
                }
            }
            x = x + x;
            ans++;
        }
        cout << -1 << endl;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

B

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define has1 __builtin_popcount
void solve()
{
    ll a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c)
    {
        cout << "YES"
             << "\n";
        return;
    }
    ll minn = min(min(a, b), c);
    int num = 0;
    if (a != minn)
    {
        if (minn * 4 == a)
        {
            num += 3;
        }
        else if (a == 3 * minn)
        {
            num += 2;
        }
        else if (a == 2 * minn)
        {
            num += 1;
        }
        else
        {
            cout << "NO" << endl;
            return;
        }
    }
    if (b != minn)
    {
        if (minn * 4 == b)
        {
            num += 3;
        }
        else if (b == 3 * minn)
        {
            num += 2;
        }
        else if (b == 2 * minn)
        {
            num += 1;
        }
        else
        {
            cout << "NO" << endl;
            return;
        }
    }
    if (c != minn)
    {
        if (minn * 4 == c)
        {
            num += 3;
        }
        else if (c == 3 * minn)
        {
            num += 2;
        }
        else if (c == 2 * minn)
        {
            num += 1;
        }
        else
        {
            cout << "NO" << endl;
            return;
        }
    }
    if (num > 3)
    {
        cout << "NO\n";
    }
    else
    {
        cout << "YES\n";
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

C

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define has1 __builtin_popcount
int min_operations(vector<vector<char>> &matrix)
{
    int n = matrix.size();
    int operations = 0;
    for (int i = 0; i < n / 2; ++i)
    {
        for (int j = 0; j < n / 2; ++j)
        {
            vector<char> chars{matrix[i][j], matrix[j][n - i - 1], matrix[n - i - 1][n - j - 1], matrix[n - j - 1][i]};
            char min_char = *min_element(chars.begin(), chars.end());
            char max_char = *max_element(chars.begin(), chars.end());

            for (auto &c : chars)
            {
                if (c != max_char)
                    operations += (max_char - c);
            }
        }
    }
    return operations;
}

const int N = 1e3 + 5;
char a[N][N];

void solve()
{
    int n;
    cin >> n;

    vector<vector<char>> v(n, vector<char>(n));

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> v[i][j];
        }
    }

    cout << min_operations(v) << endl;
}

int main()
{
    ios_base ::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;

    while (t--)
        solve();

    return 0;
}

D

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define has1 __builtin_popcount
bool isPrime(int n)
{
    if (n < 2)
    {
        return false;
    }
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
    }
    return true;
}
void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (isPrime(a[i]))
        {
            mp[a[i]]++;
            continue;
        }
        for (int j = 2; a[i] != 1; j)
        {
            if (isPrime(a[i]))
            {
                mp[a[i]]++;
                break;
            }
            if (a[i] % j == 0)
            {
                a[i] /= j;
                mp[j]++;
            }
            else
            {
                j++;
            }
        }
    }
    for (auto [x, y] : mp)
    {
        if (y % n != 0)
        {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

E

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define has1 __builtin_popcount
const int INF = 1e9;
void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> dp(n + 1, n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    dp[n] = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        dp[i] = dp[i + 1] + 1;
        if (i < n - a[i])
        {
            dp[i] = min(dp[i], dp[i + a[i] + 1]);
        }
    }
    cout << dp[0] << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值